Class: ApiMaker::CollectionCommandService

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

Instance Attribute Summary

Attributes inherited from CommandService

#ability, #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

#authorize!Object

Raises:

  • (CanCan::AccessDenied)


17
18
19
# File 'app/services/api_maker/collection_command_service.rb', line 17

def authorize!
  raise CanCan::AccessDenied, "No access to '#{@command_name}' on '#{model_class.name}'" unless @ability.can?(@command_name.to_sym, model_class)
end

#constantObject



21
22
23
# File 'app/services/api_maker/collection_command_service.rb', line 21

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

#executeObject



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

def execute
  authorize!

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

  ServicePattern::Response.new(success: true)
end