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

- (Array<Symbol>) available_choices_for(component)

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

Examples:

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

Parameters:

  • component (Symbol)

    The type of the component module

Returns:

  • (Array<Symbol>)

    Array of component choices



511
512
513
# File 'padrino-gen/lib/padrino-gen/generators/actions.rb', line 511

def available_choices_for(component)
  @available_choices[component] + [:none]
end

- (Object) component_option(name, caption, options = {})

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

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



471
472
473
474
475
476
# File 'padrino-gen/lib/padrino-gen/generators/actions.rb', line 471

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

- (Object) component_types

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the compiled list of component types which can be specified



495
496
497
# File 'padrino-gen/lib/padrino-gen/generators/actions.rb', line 495

def component_types
  @component_types
end

- (Object) require_arguments!

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

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



481
482
483
# File 'padrino-gen/lib/padrino-gen/generators/actions.rb', line 481

def require_arguments!
  @require_arguments = true
end

- (Boolean) require_arguments?

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

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

Returns:

  • (Boolean)


488
489
490
# File 'padrino-gen/lib/padrino-gen/generators/actions.rb', line 488

def require_arguments?
  @require_arguments
end