class Haml::Generators::CommandControllerGenerator

Public Class Methods

new(args, *options) click to toggle source
Calls superclass method
# File lib/generators/haml/command_controller/command_controller_generator.rb, line 18
def initialize(args, *options)
  super
  parse_command_attributes!
end

Public Instance Methods

create_template_file() click to toggle source
# File lib/generators/haml/command_controller/command_controller_generator.rb, line 23
def create_template_file
  template 'new.html.haml', File.join('app/views', class_path, "#{file_name}_command", "#{new_action}.html.haml")
end

Protected Instance Methods

parse_command_attributes!() click to toggle source
# File lib/generators/haml/command_controller/command_controller_generator.rb, line 29
def parse_command_attributes!
  self.command_attributes = (command_attributes || []).map do |attribute|
    # expected in the form "name", "name:type" or "name:type:required"
    parts = attribute.split(':')
    name = parts.first.underscore
    type = ((parts.length > 1) ? parts[1] : 'string')

    additional_options = case type.to_sym
      when :integer, :decimal, :boolean, :date, :time, :datetime
        ", :as => :#{type}"
      when :enum
        ", :collection => #{name.titleize}Enum.collection"
      when :model
        ", :collection => #{name.titleize}.all"
      else
        ''
      end

    OpenStruct.new(
      :name => name,
      :type => type,
      :inject_options => additional_options
    )
  end
end