Module: RubiGen::Lookup::ClassMethods

### Home Classes Methods

### In Files

- lib/rubigen/lookup.rb

### Methods

- #append_sources
- #application_sources
- #filtered_sources
- #instance
- #lookup
- #prepend_sources
- #reset_sources
- #sources
- #use_application_sources!
- #use_component_sources!

### Files

- History.txt
- License.txt
- Manifest.txt
- Todo.txt
- README.txt
- index.txt
- version-raw.txt
- version.txt

### Class/Module Index

Quicksearch

- RubiGen
- RubiGen::AbstractGemSource
- RubiGen::Base
- RubiGen::Commands
- RubiGen::Commands::Base
- RubiGen::Commands::Create
- RubiGen::Commands::Destroy
- RubiGen::Commands::List
- RubiGen::Commands::RewindBase
- RubiGen::Commands::Update
- RubiGen::GemPathSource
- RubiGen::GeneratedAttribute
- RubiGen::GeneratorError
- RubiGen::GeneratorTestHelper
- RubiGen::Lookup
- RubiGen::Lookup::ClassMethods
- RubiGen::Manifest
- RubiGen::Options
- RubiGen::Options::ClassMethods
- RubiGen::PathFilteredSource
- RubiGen::PathSource
- RubiGen::Scripts
- RubiGen::Scripts::Base
- RubiGen::Scripts::Destroy
- RubiGen::Scripts::Generate
- RubiGen::Scripts::Update
- RubiGen::Source
- RubiGen::Spec
- RubiGen::UsageError
- Rubigen
- Rubigen::CLI
- Dir
- Object

No matching classes.

# 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
    def append_sources(*args)
      sources.concat(args.flatten)
      invalidate_cache!
    end

application_sources(filters = []) click to toggle source

    # 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

filtered_sources(filters) click to toggle source

    # 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

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
    def instance(generator_name, args = [], runtime_options = {})
      active.lookup(generator_name).klass.new(args, full_options(runtime_options))
    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
    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

prepend_sources(*args) click to toggle source

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_sources() click to toggle source

Reset the source list.

    # File lib/rubigen/lookup.rb, line 94
    def reset_sources
      write_inheritable_attribute(:sources, [])
      invalidate_cache!
    end

sources() click to toggle source

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_sources!(*filters) click to toggle source

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_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
    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

[Validate]

Generated with the Darkfish Rdoc Generator 2.