Class: SolrMakr::ApplicationAction
- Inherits:
-
Object
- Object
- SolrMakr::ApplicationAction
- Defined in:
- lib/solr_makr/application_action.rb
Defined Under Namespace
Classes: Configurator
Instance Attribute Summary collapse
- #command_formatter ⇒ Proc private
- #default_options_formatter ⇒ Proc private
- #initial_configuration ⇒ nil readonly
- #interaction_klass ⇒ Class readonly
Instance Method Summary collapse
- #add_option!(name, **attributes) {|option| ... } ⇒ Object
- #add_options_to!(command) ⇒ void
- #configure {|Configurator.new(self)| ... } ⇒ Object
- #default_command_name ⇒ String private
- #derive_default_interaction ⇒ String private
- #execute(args, options) ⇒ SolrMakr::Commands::Buffer
- #format_command!(command) ⇒ void private
- #requires?(option_name) ⇒ Boolean
- #set_default_options!(args, options) ⇒ void private
- #setup_command!(command) ⇒ void
Instance Attribute Details
#command_formatter ⇒ Proc
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.
102 103 104 |
# File 'lib/solr_makr/application_action.rb', line 102 def command_formatter @command_formatter end |
#default_options_formatter ⇒ Proc
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.
97 98 99 |
# File 'lib/solr_makr/application_action.rb', line 97 def @default_options_formatter end |
#initial_configuration ⇒ nil (readonly)
144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/solr_makr/application_action.rb', line 144 attr_lazy_reader :initial_configuration do if requires_name? add_option! :name, short_name: 'n', description: 'Name of the collection', type: String, required: true end if specifies_configset? add_option! :configset, value_name: 'NAME', description: 'Name of the configset', type: String, required: true do |c| c.default_value = proc { SolrMakr.configuration.default_configset } end end end |
#interaction_klass ⇒ Class (readonly)
90 91 92 |
# File 'lib/solr_makr/application_action.rb', line 90 attr_lazy_reader :interaction_klass do "SolrMakr::Commands::#{interaction}".constantize end |
Instance Method Details
#add_option!(name, **attributes) {|option| ... } ⇒ Object
112 113 114 115 116 117 118 119 120 121 122 |
# 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) ⇒ void
This method returns an undefined value.
132 133 134 |
# File 'lib/solr_makr/application_action.rb', line 132 def (command) option_mapping.add_to_command! command end |
#configure {|Configurator.new(self)| ... } ⇒ Object
33 34 35 36 37 38 39 |
# 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 ⇒ String
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.
138 139 140 |
# 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 ⇒ String
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.
126 127 128 |
# File 'lib/solr_makr/application_action.rb', line 126 def derive_default_interaction name.to_s.classify end |
#execute(args, options) ⇒ SolrMakr::Commands::Buffer
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/solr_makr/application_action.rb', line 17 def execute(args, ) buffer = SolrMakr::Commands::Buffer.new execution = SolrMakr::Commands::Execute.run action: self, command_args: args, command_options: buffer.import execution.buffer unless execution.valid? execution.errors..each do |error| buffer.error error end end return buffer end |
#format_command!(command) ⇒ void
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.
This method returns an undefined value.
80 81 82 83 84 85 86 |
# 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) ⇒ Boolean
57 58 59 |
# 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) ⇒ void
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.
This method returns an undefined value.
65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/solr_makr/application_action.rb', line 65 def (args, ) option_mapping.each do |option| option.set_default!(args, ) end if .respond_to?(:call) instance_exec(args, , &) end return nil end |
#setup_command!(command) ⇒ void
This method returns an undefined value.
43 44 45 46 47 48 49 50 51 52 53 54 55 |
# 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 command format_command! command command.when_called self, :execute end |