Class: LcpRuby::BatchActions::CustomActionDispatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/lcp_ruby/batch_actions/custom_action_dispatcher.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(action_key:, records:, current_user:, params:, model_class:, model_definition:, batch_operation: nil, &progress) ⇒ CustomActionDispatcher

Returns a new instance of CustomActionDispatcher.



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/lcp_ruby/batch_actions/custom_action_dispatcher.rb', line 7

def initialize(action_key:, records:, current_user:, params:,
               model_class:, model_definition:, batch_operation: nil, &progress)
  @action_key = action_key
  @records = records
  @current_user = current_user
  @params = params
  @model_class = model_class
  @model_definition = model_definition
  @batch_operation = batch_operation
  @progress = progress
end

Instance Attribute Details

#action_keyObject (readonly)

Returns the value of attribute action_key.



4
5
6
# File 'lib/lcp_ruby/batch_actions/custom_action_dispatcher.rb', line 4

def action_key
  @action_key
end

#batch_operationObject (readonly)

Returns the value of attribute batch_operation.



4
5
6
# File 'lib/lcp_ruby/batch_actions/custom_action_dispatcher.rb', line 4

def batch_operation
  @batch_operation
end

#current_userObject (readonly)

Returns the value of attribute current_user.



4
5
6
# File 'lib/lcp_ruby/batch_actions/custom_action_dispatcher.rb', line 4

def current_user
  @current_user
end

#model_classObject (readonly)

Returns the value of attribute model_class.



4
5
6
# File 'lib/lcp_ruby/batch_actions/custom_action_dispatcher.rb', line 4

def model_class
  @model_class
end

#model_definitionObject (readonly)

Returns the value of attribute model_definition.



4
5
6
# File 'lib/lcp_ruby/batch_actions/custom_action_dispatcher.rb', line 4

def model_definition
  @model_definition
end

#paramsObject (readonly)

Returns the value of attribute params.



4
5
6
# File 'lib/lcp_ruby/batch_actions/custom_action_dispatcher.rb', line 4

def params
  @params
end

#progressObject (readonly)

Returns the value of attribute progress.



4
5
6
# File 'lib/lcp_ruby/batch_actions/custom_action_dispatcher.rb', line 4

def progress
  @progress
end

#recordsObject (readonly)

Returns the value of attribute records.



4
5
6
# File 'lib/lcp_ruby/batch_actions/custom_action_dispatcher.rb', line 4

def records
  @records
end

Instance Method Details

#callObject

Raises:



19
20
21
22
23
24
25
26
27
28
# File 'lib/lcp_ruby/batch_actions/custom_action_dispatcher.rb', line 19

def call
  action_class = Actions::ActionRegistry.action_for(action_key)
  raise LcpRuby::Error, "Action '#{action_key}' not found" unless action_class

  if action_class.batch_capable?
    execute_bulk(action_class)
  else
    execute_per_record(action_class)
  end
end