Class: Picky::Generators::Selector
- Inherits:
-
Object
- Object
- Picky::Generators::Selector
- Defined in:
- lib/picky-generators/generators/selector.rb
Overview
Selects the right generator.
Instance Attribute Summary collapse
-
#types ⇒ Object
readonly
Returns the value of attribute types.
Instance Method Summary collapse
-
#generate(*args) ⇒ Object
Run the generators with this command.
- #generator_for(identifier = nil, *args) ⇒ Object
- #generator_for_class(klass, *args) ⇒ Object
-
#initialize ⇒ Selector
constructor
A new instance of Selector.
Constructor Details
#initialize ⇒ Selector
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
#types ⇒ Object (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 |