diff options
author | José Valim <jose.valim@gmail.com> | 2009-07-15 11:33:36 +0200 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2009-07-15 11:33:36 +0200 |
commit | 0702e04e0d671227259f71f614adfe3f35f88b48 (patch) | |
tree | 9f3c34075fbb4ed4c227f66fd3168de86f8ab1f4 /railties/lib/vendor | |
parent | a06c825b464758a0c22f8b089a596e46f1bba5cb (diff) | |
download | rails-0702e04e0d671227259f71f614adfe3f35f88b48.tar.gz rails-0702e04e0d671227259f71f614adfe3f35f88b48.tar.bz2 rails-0702e04e0d671227259f71f614adfe3f35f88b48.zip |
Refactored some generators to make use of improved invocations on thor.
Diffstat (limited to 'railties/lib/vendor')
-rw-r--r-- | railties/lib/vendor/thor-0.11.1/lib/thor/actions.rb | 64 | ||||
-rw-r--r-- | railties/lib/vendor/thor-0.11.1/lib/thor/base.rb | 21 |
2 files changed, 62 insertions, 23 deletions
diff --git a/railties/lib/vendor/thor-0.11.1/lib/thor/actions.rb b/railties/lib/vendor/thor-0.11.1/lib/thor/actions.rb index b64ea1c878..83d082382c 100644 --- a/railties/lib/vendor/thor-0.11.1/lib/thor/actions.rb +++ b/railties/lib/vendor/thor-0.11.1/lib/thor/actions.rb @@ -5,17 +5,13 @@ Dir[File.join(File.dirname(__FILE__), "actions", "*.rb")].each do |action| end class Thor - # Some actions require that a class method called source root is defined in - # the class. Remember to always cache the source root value, because Ruby - # __FILE__ always return the relative path, which may lead to mistakes if you - # are calling an action inside the "inside(path)" method. - # module Actions attr_accessor :behavior # On inclusion, add some options to base. # def self.included(base) #:nodoc: + base.extend ClassMethods return unless base.respond_to?(:class_option) base.class_option :pretend, :type => :boolean, :aliases => "-p", :group => :runtime, @@ -31,6 +27,50 @@ class Thor :desc => "Supress status output" end + module ClassMethods + # Hold source paths used by Thor::Actions. + # + def source_paths + @source_paths ||= from_superclass(:source_paths, []) + end + + # On inheritance, add source root to source paths so dynamic source_root + # (that depends on the class name, for example) are cached properly. + # + def inherited(base) #:nodoc: + super + base.source_paths + if base.respond_to?(:source_root) && !base.source_paths.include?(base.source_root) + base.source_paths.unshift(base.source_root) + end + end + + # Deal with source root cache in source_paths. source_paths in the + # inheritance chain are tricky to implement because: + # + # 1) We have to ensure that paths from the parent class appears later in + # the source paths array. + # + # 2) Whenever source_root is added, it has to be cached because __FILE__ + # in ruby returns relative locations. + # + # 3) If someone wants to add source paths dinamically, added paths have + # to come before the source root. + # + # This method basically check if source root was added and put it between + # the inherited paths and the user added paths. + # + def singleton_method_added(method) #:nodoc: + if method == :source_root + inherited_paths = from_superclass(:source_paths, []) + + self.source_paths.reject!{ |path| inherited_paths.include?(path) } + self.source_paths.push(*self.source_root) + self.source_paths.concat(inherited_paths) + end + end + end + # Extends initializer to add more configuration options. # # ==== Configuration @@ -88,14 +128,13 @@ class Thor remove_dot ? (path[2..-1] || '') : path end - # Receives a file or directory and serach for it in the source paths. Paths - # added for last are the one searched first. + # Receives a file or directory and search for it in the source paths. # def find_in_source_paths(file) relative_root = relative_to_original_destination_root(destination_root, false) source_file = nil - self.class.source_paths.reverse_each do |source| + self.class.source_paths.each do |source| source_file = File.expand_path(file, File.join(source, relative_root)) return source_file if File.exists?(source_file) end @@ -123,6 +162,15 @@ class Thor @destination_stack.pop end + # Same as inside, but log status and use padding. + # + def inside_with_padding(dir='', log_status=true, &block) + say_status :inside, dir, log_status + shell.padding += 1 + inside(dir, &block) + shell.padding -= 1 + end + # Goes to the root and execute the given block. # def in_root diff --git a/railties/lib/vendor/thor-0.11.1/lib/thor/base.rb b/railties/lib/vendor/thor-0.11.1/lib/thor/base.rb index fcd2a82be0..caf298dda8 100644 --- a/railties/lib/vendor/thor-0.11.1/lib/thor/base.rb +++ b/railties/lib/vendor/thor-0.11.1/lib/thor/base.rb @@ -37,15 +37,17 @@ class Thor parse_options = self.class.class_options - options = if options.is_a?(Array) + if options.is_a?(Array) task_options = config.delete(:task_options) # hook for start parse_options = parse_options.merge(task_options) if task_options - Thor::Options.parse(parse_options, options) + array_options, hash_options = options, {} else - Thor::Options.parse(parse_options, []).merge(options) + array_options, hash_options = [], options end - self.options = Thor::CoreExt::HashWithIndifferentAccess.new(options).freeze + options = Thor::Options.parse(parse_options, array_options) + self.options = Thor::CoreExt::HashWithIndifferentAccess.new(options).merge!(hash_options) + self.options.freeze end class << self @@ -81,10 +83,6 @@ class Thor file = caller[1].match(/(.*):\d+/)[1] Thor::Base.subclasses << klass unless Thor::Base.subclasses.include?(klass) - if klass.respond_to?(:source_root) && !klass.source_paths.include?(klass.source_root) - klass.source_paths.unshift(klass.source_root) - end - file_subclasses = Thor::Base.subclass_files[File.expand_path(file)] file_subclasses << klass unless file_subclasses.include?(klass) end @@ -341,13 +339,6 @@ class Thor end end - # Hold source paths used by Thor::Actions. Paths added for last are the - # one searched first. - # - def source_paths - @source_paths ||= [] - end - # Default way to start generators from the command line. # def start(given_args=ARGV, config={}) #:nodoc: |