Add a source to the end of the list.
# File lib/rubigen/lookup.rb, line 80 def append_sources(*args) sources.concat(args.flatten) invalidate_cache! end
# File lib/rubigen/lookup.rb, line 105 def application_sources(filters = []) filters.unshift 'app' app_sources = [] app_sources << PathSource.new(:builtin, File.join(File.dirname(__FILE__), ].. .. app_generators])) app_sources << filtered_sources(filters) app_sources.flatten end
# File lib/rubigen/lookup.rb, line 138 def filtered_sources(filters) new_sources = [] new_sources << PathFilteredSource.new(:user, "#{Dir.user_home}/.rubigen/", *filters) if Object.const_defined?(:Gem) new_sources << GemPathSource.new(*filters) end new_sources end
Convenience method to lookup and instantiate a generator.
# File lib/rubigen/lookup.rb, line 164 def instance(generator_name, args = [], runtime_options = {}) active.lookup(generator_name).klass.new(args, full_options(runtime_options)) end
Lookup knows how to find generators' Specs from a list of Sources. Searches the sources, in order, for the first matching name.
# File lib/rubigen/lookup.rb, line 149 def lookup(generator_name) @found ||= {} generator_name = generator_name.to_s.downcase @found[generator_name] ||= cache.find { |spec| spec.name == generator_name } unless @found[generator_name] chars = generator_name.scan(/./).map{|c|"#{c}.*?"} rx = /^#{chars}$/ gns = cache.select {|spec| spec.name =~ rx } @found[generator_name] ||= gns.first if gns.length == 1 raise GeneratorError, "Pattern '#{generator_name}' matches more than one generator: #{gns.map{|sp|sp.name}.join(', ')}" if gns.length > 1 end @found[generator_name] or raise GeneratorError, "Couldn't find '#{generator_name}' generator" end
Add a source to the beginning of the list.
# File lib/rubigen/lookup.rb, line 86 def prepend_sources(*args) sources = self.sources reset_sources write_inheritable_array(:sources, args.flatten + sources) invalidate_cache! end
Reset the source list.
# File lib/rubigen/lookup.rb, line 94 def reset_sources write_inheritable_attribute(:sources, []) invalidate_cache! end
The list of sources where we look, in order, for generators.
# File lib/rubigen/lookup.rb, line 62 def sources if read_inheritable_attribute(:sources).blank? if superclass == RubiGen::Base superclass_sources = superclass.sources diff = superclass_sources.inject([]) do |mem, source| found = false application_sources.each { |app_source| found ||= true if app_source == source} mem << source unless found mem end write_inheritable_attribute(:sources, diff) end active.use_component_sources! if read_inheritable_attribute(:sources).blank? end read_inheritable_attribute(:sources) end
Use application generators (app, ?).
# File lib/rubigen/lookup.rb, line 100 def use_application_sources!(*filters) reset_sources write_inheritable_attribute(:sources, application_sources(filters)) end
Use component generators (test_unit, etc).
Current application. If APP_ROOT is defined we know we're generating in the context of this application, so search APP_ROOT/generators.
User home directory. Search ~/.rubigen/generators.
RubyGems. Search for gems containing /{scope}_generators folder.
Builtins. None currently.
Search can be filtered by passing one or more prefixes. e.g. use_component_sources!(:rubygems) means it will also search in the following folders:
User home directory. Search ~/.rubigen/rubygems_generators.
RubyGems. Search for gems containing /rubygems_generators folder.
# File lib/rubigen/lookup.rb, line 126 def use_component_sources!(*filters) reset_sources new_sources = [] if defined? ::APP_ROOT new_sources << PathSource.new(:root, "#{::APP_ROOT}/generators") new_sources << PathSource.new(:vendor, "#{::APP_ROOT}/vendor/generators") new_sources << PathSource.new(:plugins, "#{::APP_ROOT}/vendor/plugins/*/**/generators") end new_sources << filtered_sources(filters) write_inheritable_attribute(:sources, new_sources.flatten) end
Generated with the Darkfish Rdoc Generator 2.