RubiGen::Lookup::ClassMethods

Public Instance Methods

append_sources(*args) click to toggle source

Add a source to the end of the list.

    # File lib/rubigen/lookup.rb, line 80
80:       def append_sources(*args)
81:         sources.concat(args.flatten)
82:         invalidate_cache!
83:       end
application_sources(filters = []) click to toggle source
     # File lib/rubigen/lookup.rb, line 105
105:       def application_sources(filters = [])
106:         filters.unshift 'app'
107:         app_sources = []
108:         app_sources << PathSource.new(:builtin, File.join(File.dirname(__FILE__), ].. .. app_generators]))
109:         app_sources << filtered_sources(filters)
110:         app_sources.flatten
111:       end
filtered_sources(filters) click to toggle source
     # File lib/rubigen/lookup.rb, line 138
138:       def filtered_sources(filters)
139:         new_sources = []
140:         new_sources << PathFilteredSource.new(:user, "#{Dir.user_home}/.rubigen/", *filters)
141:         if Object.const_defined?(:Gem)
142:           new_sources << GemPathSource.new(*filters)
143:         end
144:         new_sources
145:       end
instance(generator_name, args = [], runtime_options = {}) click to toggle source

Convenience method to lookup and instantiate a generator.

     # File lib/rubigen/lookup.rb, line 164
164:       def instance(generator_name, args = [], runtime_options = {})
165:         active.lookup(generator_name).klass.new(args, full_options(runtime_options))
166:       end
lookup(generator_name) click to toggle source

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
149:       def lookup(generator_name)
150:         @found ||= {}
151:         generator_name = generator_name.to_s.downcase
152:         @found[generator_name] ||= cache.find { |spec| spec.name == generator_name }
153:         unless @found[generator_name] 
154:           chars = generator_name.scan(/./).map{|c|"#{c}.*?"}
155:           rx = /^#{chars}$/
156:           gns = cache.select {|spec| spec.name =~ rx }
157:           @found[generator_name] ||= gns.first if gns.length == 1
158:           raise GeneratorError, "Pattern '#{generator_name}' matches more than one generator: #{gns.map{|sp|sp.name}.join(', ')}" if gns.length > 1
159:         end
160:         @found[generator_name] or raise GeneratorError, "Couldn't find '#{generator_name}' generator"
161:       end
prepend_sources(*args) click to toggle source

Add a source to the beginning of the list.

    # File lib/rubigen/lookup.rb, line 86
86:       def prepend_sources(*args)
87:         sources = self.sources
88:         reset_sources
89:         write_inheritable_array(:sources, args.flatten + sources)
90:         invalidate_cache!
91:       end
reset_sources() click to toggle source

Reset the source list.

    # File lib/rubigen/lookup.rb, line 94
94:       def reset_sources
95:         write_inheritable_attribute(:sources, [])
96:         invalidate_cache!
97:       end
sources() click to toggle source

The list of sources where we look, in order, for generators.

    # File lib/rubigen/lookup.rb, line 62
62:       def sources
63:         if read_inheritable_attribute(:sources).blank?
64:           if superclass == RubiGen::Base
65:             superclass_sources = superclass.sources
66:             diff = superclass_sources.inject([]) do |mem, source|
67:               found = false
68:               application_sources.each { |app_source| found ||= true if app_source == source}
69:               mem << source unless found
70:               mem
71:             end
72:             write_inheritable_attribute(:sources, diff)
73:           end
74:           active.use_component_sources! if read_inheritable_attribute(:sources).blank?
75:         end
76:         read_inheritable_attribute(:sources)
77:       end
use_application_sources!(*filters) click to toggle source

Use application generators (app, ?).

     # File lib/rubigen/lookup.rb, line 100
100:       def use_application_sources!(*filters)
101:         reset_sources
102:         write_inheritable_attribute(:sources, application_sources(filters))
103:       end
use_component_sources!(*filters) click to toggle source

Use component generators (test_unit, etc).

  1. Current application. If APP_ROOT is defined we know we’re generating in the context of this application, so search APP_ROOT/generators.

  2. User home directory. Search ~/.rubigen/generators.

  3. RubyGems. Search for gems containing /{scope}_generators folder.

  4. 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:

  1. User home directory. Search ~/.rubigen/rubygems_generators.

  2. RubyGems. Search for gems containing /rubygems_generators folder.

     # File lib/rubigen/lookup.rb, line 126
126:       def use_component_sources!(*filters)
127:         reset_sources
128:         new_sources = []
129:         if defined? ::APP_ROOT
130:           new_sources << PathSource.new(:root, "#{::APP_ROOT}/generators")
131:           new_sources << PathSource.new(:vendor, "#{::APP_ROOT}/vendor/generators")
132:           new_sources << PathSource.new(:plugins, "#{::APP_ROOT}/vendor/plugins/*/**/generators")
133:         end
134:         new_sources << filtered_sources(filters)
135:         write_inheritable_attribute(:sources, new_sources.flatten)
136:       end

Private Instance Methods

cache() click to toggle source

Lookup and cache every generator from the source list.

     # File lib/rubigen/lookup.rb, line 170
170:         def cache
171:           @cache ||= sources.inject([]) { |cache, source| cache + source.to_a }
172:         end
invalidate_cache!() click to toggle source

Clear the cache whenever the source list changes.

     # File lib/rubigen/lookup.rb, line 175
175:         def invalidate_cache!
176:           @cache = nil
177:         end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.