Class: ApiMaker::CollectionCommandService
Instance Attribute Summary
#ability, #api_maker_args, #command_name, #command_response, #commands, #controller, #resource_name
Instance Method Summary
collapse
#initialize, #model_class, #namespace, #resource
#api_maker_json
Instance Method Details
#authorized? ⇒ Boolean
21
22
23
|
# File 'app/services/api_maker/collection_command_service.rb', line 21
def authorized?
ability.can?(command_name.to_sym, model_class)
end
|
#constant ⇒ Object
25
26
27
|
# File 'app/services/api_maker/collection_command_service.rb', line 25
def constant
@constant ||= "Commands::#{namespace}::#{command_name.camelize}".constantize
end
|
#fail_with_no_access ⇒ Object
29
30
31
32
33
34
35
36
37
|
# File 'app/services/api_maker/collection_command_service.rb', line 29
def fail_with_no_access
commands.each_key do |command_id|
command_response.error_for_command(
command_id,
success: false,
errors: ["No access to '#{command_name}' on '#{model_class.name}'"]
)
end
end
|
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
# File 'app/services/api_maker/collection_command_service.rb', line 2
def perform
ApiMaker::Configuration.profile(-> { "CollectionCommand: #{namespace}::#{command_name}" }) do
if authorized?
constant.execute_in_thread!(
ability: ability,
api_maker_args: api_maker_args,
collection: nil,
commands: commands,
command_response: command_response,
controller: controller
)
else
fail_with_no_access
end
succeed!
end
end
|