Class: ApiMaker::MemberCommandService

Inherits:
CommandService show all
Defined in:
app/services/api_maker/member_command_service.rb

Instance Attribute Summary

Attributes inherited from CommandService

#ability, #api_maker_args, #command_name, #command_response, #commands, #controller, #resource_name

Instance Method Summary collapse

Methods inherited from CommandService

#initialize, #model_class, #namespace, #resource

Methods inherited from ApplicationService

#api_maker_json

Constructor Details

This class inherits a constructor from ApiMaker::CommandService

Instance Method Details

#constantObject



20
21
22
# File 'app/services/api_maker/member_command_service.rb', line 20

def constant
  @constant ||= "Commands::#{namespace}::#{command_name.camelize}".constantize
end

#idsObject



24
25
26
# File 'app/services/api_maker/member_command_service.rb', line 24

def ids
  @commands.values.map { |command| command.fetch("primary_key") }
end

#performObject



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'app/services/api_maker/member_command_service.rb', line 2

def perform
  ApiMaker::Configuration.profile(-> { "MemberCommand execute: #{model_class.name}##{command_name}" }) do
    ability_name = command_name.to_sym
    collection = model_class.accessible_by(@ability, ability_name).where(model_class.primary_key => ids)

    constant.execute_in_thread!(
      ability: ability,
      api_maker_args: api_maker_args,
      collection: collection,
      commands: commands,
      command_response: command_response,
      controller: controller
    )

    succeed!
  end
end