Class: Picky::Generators::Selector

Inherits:
Object
  • Object
show all
Defined in:
lib/picky-generators/generators/selector.rb

Overview

Selects the right generator.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSelector

Returns a new instance of Selector.



11
12
13
14
15
16
17
# File 'lib/picky-generators/generators/selector.rb', line 11

def initialize
  @types = {
    :client               => [Client::Sinatra, :sinatra_client_name],
    :server               => [Server::Sinatra, :sinatra_server_name],
    :all_in_one           => [AllInOne::Sinatra, :"directory_name (use e.g. for Heroku)"]
  }
end

Instance Attribute Details

#typesObject (readonly)

Returns the value of attribute types.



9
10
11
# File 'lib/picky-generators/generators/selector.rb', line 9

def types
  @types
end

Instance Method Details

#generate(*args) ⇒ Object

Run the generators with this command.

This will “route” the commands to the right specific generator.



23
24
25
26
# File 'lib/picky-generators/generators/selector.rb', line 23

def generate *args
  generator = generator_for *args
  generator.generate
end

#generator_for(identifier = nil, *args) ⇒ Object



30
31
32
33
34
35
36
# File 'lib/picky-generators/generators/selector.rb', line 30

def generator_for identifier = nil, *args
  generator_info = types[identifier.to_sym]
  generator_class = generator_info.first
  generator_for_class generator_class, identifier, *args
rescue
  raise NotFoundException.new(self)
end

#generator_for_class(klass, *args) ⇒ Object



40
41
42
# File 'lib/picky-generators/generators/selector.rb', line 40

def generator_for_class klass, *args
  klass.new *args
end