Module: Padrino::Generators::Actions::ClassMethods
- Defined in:
- padrino-gen/lib/padrino-gen/generators/actions.rb
Overview
Class methods for Thor generators to support the generators and component choices.
Instance Method Summary collapse
-
#available_choices_for(component) ⇒ Array<Symbol>
Returns the list of available choices for the given component (including none).
-
#component_option(name, caption, options = {}) ⇒ Object
Defines a class option to allow a component to be chosen and add to component type list.
-
#component_types ⇒ Object
Returns the compiled list of component types which can be specified.
-
#defines_component_options(options = {}) ⇒ Object
Definitions for the available customizable components.
-
#require_arguments! ⇒ Object
Tells Padrino that for this Thor::Group it is a necessary task to run.
-
#require_arguments? ⇒ Boolean
Returns true if we need an arguments for our Thor::Group.
Instance Method Details
#available_choices_for(component) ⇒ Array<Symbol>
Returns the list of available choices for the given component (including none).
616 617 618 |
# File 'padrino-gen/lib/padrino-gen/generators/actions.rb', line 616 def available_choices_for(component) @available_choices[component] + [:none] end |
#component_option(name, caption, options = {}) ⇒ Object
Defines a class option to allow a component to be chosen and add to component type list. Also builds the available_choices hash of which component choices are supported.
559 560 561 562 563 564 |
# File 'padrino-gen/lib/padrino-gen/generators/actions.rb', line 559 def component_option(name, , = {}) (@component_types ||= []) << name # TODO use ordered hash and combine with choices below (@available_choices ||= Hash.new)[name] = [:choices] description = "The #{} component (#{[:choices].join(', ')}, none)" class_option name, :default => [:default] || [:choices].first, :aliases => [:aliases], :desc => description end |
#component_types ⇒ Object
Returns the compiled list of component types which can be specified.
600 601 602 |
# File 'padrino-gen/lib/padrino-gen/generators/actions.rb', line 600 def component_types @component_types end |
#defines_component_options(options = {}) ⇒ Object
Definitions for the available customizable components.
569 570 571 572 573 574 575 576 577 578 579 580 581 |
# File 'padrino-gen/lib/padrino-gen/generators/actions.rb', line 569 def ( = {}) [ [ :orm, 'database engine', { :aliases => '-d', :default => :none }], [ :test, 'testing framework', { :aliases => '-t', :default => :none }], [ :mock, 'mocking library', { :aliases => '-m', :default => :none }], [ :script, 'javascript library', { :aliases => '-s', :default => :none }], [ :renderer, 'template engine', { :aliases => '-e', :default => :none }], [ :stylesheet, 'stylesheet engine', { :aliases => '-c', :default => :none }] ].each do |name, , opts| opts[:default] = '' if [:default] == false component_option name, , opts.merge(:choices => Dir["#{File.dirname(__FILE__)}/components/#{name.to_s.pluralize}/*.rb"].map{|lib| File.basename(lib, '.rb').to_sym}) end end |
#require_arguments! ⇒ Object
Tells Padrino that for this Thor::Group it is a necessary task to run.
586 587 588 |
# File 'padrino-gen/lib/padrino-gen/generators/actions.rb', line 586 def require_arguments! @require_arguments = true end |
#require_arguments? ⇒ Boolean
Returns true if we need an arguments for our Thor::Group.
593 594 595 |
# File 'padrino-gen/lib/padrino-gen/generators/actions.rb', line 593 def require_arguments? @require_arguments end |