class Riveter::Generators::CommandGenerator

Public Class Methods

new(args, *options) click to toggle source
Calls superclass method
# File lib/generators/riveter/command/command_generator.rb, line 16
def initialize(args, *options)
  super
  parse_command_attributes!
end

Public Instance Methods

create_command_file() click to toggle source
# File lib/generators/riveter/command/command_generator.rb, line 21
def create_command_file
  template 'command.rb', File.join('app/commands', class_path, "#{file_name}_command.rb")
end
create_locale_file() click to toggle source
# File lib/generators/riveter/command/command_generator.rb, line 30
def create_locale_file
  template 'commands.en.yml', File.join('config/locales', 'commands.en.yml') unless locale_file_exists?
end
create_module_file() click to toggle source
# File lib/generators/riveter/command/command_generator.rb, line 25
def create_module_file
  return if regular_class_path.empty?
  template 'module.rb', File.join('app/commands', "#{class_path.join('/')}.rb") if behavior == :invoke
end

Protected Instance Methods

locale_file_exists?() click to toggle source
# File lib/generators/riveter/command/command_generator.rb, line 50
def locale_file_exists?
  File.exists?(File.join(destination_root, 'config', 'locales', 'commands.en.yml'))
end
parse_command_attributes!() click to toggle source
# File lib/generators/riveter/command/command_generator.rb, line 38
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(':')
    OpenStruct.new(
      :name => parts.first.underscore,
      :type => ((parts.length > 1) ? parts[1] : 'string'),
      :inject_options => ((parts.length == 3 && parts[2] == 'required') ? ', :required => true' : '')
    )
  end
end