Class: SolrMakr::ApplicationAction

Inherits:
Object
  • Object
show all
Defined in:
lib/solr_makr/application_action.rb

Defined Under Namespace

Classes: Configurator

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#command_formatterProc

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:

  • (Proc)


102
103
104
# File 'lib/solr_makr/application_action.rb', line 102

def command_formatter
  @command_formatter
end

#default_options_formatterProc

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:

  • (Proc)


97
98
99
# File 'lib/solr_makr/application_action.rb', line 97

def default_options_formatter
  @default_options_formatter
end

#initial_configurationnil (readonly)

Returns:

  • (nil)


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_klassClass (readonly)

Returns:

  • (Class)


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

Parameters:

  • name (Symbol)
  • attributes (Hash)

Yield Parameters:

Yield Returns:

  • (void)


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.

Parameters:

  • command (Commander::Command)


132
133
134
# File 'lib/solr_makr/application_action.rb', line 132

def add_options_to!(command)
  option_mapping.add_to_command! command
end

#configure {|Configurator.new(self)| ... } ⇒ Object

Yields:



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_nameString

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:

  • (String)


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_interactionString

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:

  • (String)


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, 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) ⇒ 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.

Parameters:

  • command (Commander::Command)


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

Returns:

  • (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.

Parameters:

  • args (<String>)
  • options (Commander::Command::Options)


65
66
67
68
69
70
71
72
73
74
75
# 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) ⇒ void

This method returns an undefined value.

Parameters:

  • command (Commander::Command)


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

  add_options_to! command

  format_command! command

  command.when_called self, :execute
end