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

Instance Method Details

#available_choices_for(component) ⇒ Array<Symbol>

Returns the list of available choices for the given component (including none).

Examples:

available_choices_for :test
=> [:shoulda, :bacon, :minitest]

Parameters:

  • component (Symbol)

    The type of the component module.

Returns:

  • (Array<Symbol>)

    Array of component choices.



636
637
638
# File 'padrino-gen/lib/padrino-gen/generators/actions.rb', line 636

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.

Examples:

component_option :test, "Testing framework", :aliases => '-t', :choices => [:bacon, :shoulda]

Parameters:

  • name (Symbol)

    Name of component.

  • caption (String)

    Description of the component.

  • options (Hash) (defaults to: {})

    Additional parameters for component choice.



579
580
581
582
583
584
# File 'padrino-gen/lib/padrino-gen/generators/actions.rb', line 579

def component_option(name, caption, options = {})
  (@component_types   ||= []) << name # TODO use ordered hash and combine with choices below
  (@available_choices ||= Hash.new)[name] = options[:choices]
  description = "The #{caption} component (#{options[:choices].join(', ')}, none)"
  class_option name, :default => options[:default] || options[:choices].first, :aliases => options[:aliases], :desc => description
end

#component_typesObject

Returns the compiled list of component types which can be specified.



620
621
622
# File 'padrino-gen/lib/padrino-gen/generators/actions.rb', line 620

def component_types
  @component_types
end

#defines_component_options(options = {}) ⇒ Object

Definitions for the available customizable components.



589
590
591
592
593
594
595
596
597
598
599
600
601
# File 'padrino-gen/lib/padrino-gen/generators/actions.rb', line 589

def defines_component_options(options = {})
  [
    [ :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, caption, opts|
    opts[:default] = '' if options[:default] == false
    component_option name, caption, 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

Tell Padrino that for this Thor::Group it is a necessary task to run.



606
607
608
# File 'padrino-gen/lib/padrino-gen/generators/actions.rb', line 606

def require_arguments!
  @require_arguments = true
end

#require_arguments?Boolean

Return true if we need an arguments for our Thor::Group.

Returns:

  • (Boolean)


613
614
615
# File 'padrino-gen/lib/padrino-gen/generators/actions.rb', line 613

def require_arguments?
  @require_arguments
end