class SolrMakr::ApplicationAction

Attributes

command_formatter[RW]

@!attribute [rw] command_formatter @api private @return [Proc]

default_options_formatter[RW]

@!attribute [rw] default_options_formatter @api private @return [Proc]

Public Instance Methods

add_option!(name, **attributes) { |option| ... } click to toggle source

@param [Symbol] name @param [Hash] attributes @yieldparam [SolrMakr::OptionDefinition] option @yieldreturn [void]

# File lib/solr_makr/application_action.rb, line 112
def add_option!(name, **attributes, &configurator)
  attributes[:name] = name

  option = SolrMakr::OptionDefinition.new(attributes)

  yield option if block_given?

  option_mapping << option

  return nil
end
add_options_to!(command) click to toggle source

@param [Commander::Command] command @return [void]

# File lib/solr_makr/application_action.rb, line 132
def add_options_to!(command)
  option_mapping.add_to_command! command
end
configure() { |configurator| ... } click to toggle source
# File lib/solr_makr/application_action.rb, line 33
def configure(&block)
  initial_configuration

  yield Configurator.new(self) if block_given?

  return self
end
default_command_name() click to toggle source

@api private @return [String]

# File lib/solr_makr/application_action.rb, line 138
def default_command_name
  name.to_s.gsub(/_collections?\z/, '').humanize.downcase
end
derive_default_interaction() click to toggle source

@api private @return [String]

# File lib/solr_makr/application_action.rb, line 126
def derive_default_interaction
  name.to_s.classify
end
execute(args, options) click to toggle source

@return [SolrMakr::Commands::Buffer]

# File lib/solr_makr/application_action.rb, line 17
def execute(args, options)
  buffer    = SolrMakr::Commands::Buffer.new

  execution = SolrMakr::Commands::Execute.run action: self, command_args: args, command_options: options

  buffer.import execution.buffer

  unless execution.valid?
    execution.errors.full_messages.each do |error|
      buffer.error error
    end
  end

  return buffer
end
format_command!(command) click to toggle source

@api private @param [Commander::Command] command @return [void]

# File lib/solr_makr/application_action.rb, line 80
def format_command!(command)
  if command_formatter.respond_to?(:call)
    command_formatter.call(command)
  end

  return nil
end
requires?(option_name) click to toggle source
# File lib/solr_makr/application_action.rb, line 57
def requires?(option_name)
  option_mapping[option_name].try(:required?)
end
set_default_options!(args, options) click to toggle source

@api private @param [<String>] args @param [Commander::Command::Options] options @return [void]

# File lib/solr_makr/application_action.rb, line 65
def set_default_options!(args, options)
  option_mapping.each do |option|
    option.set_default!(args, options)
  end

  if default_options_formatter.respond_to?(:call)
    instance_exec(args, options, &default_options_formatter)
  end

  return nil
end
setup_command!(command) click to toggle source

@param [Commander::Command] command @return [void]

# File lib/solr_makr/application_action.rb, line 43
def setup_command!(command)
  command.syntax = "#{SolrMakr::BIN_NAME} #{command_name}"

  if description.present?
    command.description = description
  end

  add_options_to! command

  format_command! command

  command.when_called self, :execute
end