Class: ApiMaker::CommandService

Inherits:
ApplicationService show all
Defined in:
app/services/api_maker/command_service.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from ApplicationService

#api_maker_json

Constructor Details

#initialize(ability:, api_maker_args:, commands:, command_name:, command_response:, controller:, resource_name:) ⇒ CommandService

Returns a new instance of CommandService.



4
5
6
7
8
9
10
11
12
# File 'app/services/api_maker/command_service.rb', line 4

def initialize(ability:, api_maker_args:, commands:, command_name:, command_response:, controller:, resource_name:)
  @ability = ability
  @api_maker_args = api_maker_args
  @command_name = command_name
  @command_response = command_response
  @commands = commands
  @controller = controller
  @resource_name = resource_name
end

Instance Attribute Details

#abilityObject (readonly)

Returns the value of attribute ability.



2
3
4
# File 'app/services/api_maker/command_service.rb', line 2

def ability
  @ability
end

#api_maker_argsObject (readonly)

Returns the value of attribute api_maker_args.



2
3
4
# File 'app/services/api_maker/command_service.rb', line 2

def api_maker_args
  @api_maker_args
end

#command_nameObject (readonly)

Returns the value of attribute command_name.



2
3
4
# File 'app/services/api_maker/command_service.rb', line 2

def command_name
  @command_name
end

#command_responseObject (readonly)

Returns the value of attribute command_response.



2
3
4
# File 'app/services/api_maker/command_service.rb', line 2

def command_response
  @command_response
end

#commandsObject (readonly)

Returns the value of attribute commands.



2
3
4
# File 'app/services/api_maker/command_service.rb', line 2

def commands
  @commands
end

#controllerObject (readonly)

Returns the value of attribute controller.



2
3
4
# File 'app/services/api_maker/command_service.rb', line 2

def controller
  @controller
end

#resource_nameObject (readonly)

Returns the value of attribute resource_name.



2
3
4
# File 'app/services/api_maker/command_service.rb', line 2

def resource_name
  @resource_name
end

Instance Method Details

#model_classObject



28
29
30
# File 'app/services/api_maker/command_service.rb', line 28

def model_class
  @model_class ||= resource.model_class
end

#namespaceObject



14
15
16
# File 'app/services/api_maker/command_service.rb', line 14

def namespace
  @namespace ||= resource_name.underscore.camelize
end

#resourceObject



18
19
20
21
22
23
24
25
26
# File 'app/services/api_maker/command_service.rb', line 18

def resource
  @resource ||= begin
    resource_class_name = "Resources::#{resource_name.underscore.singularize.camelize}Resource"
    resource = resource_class_name.safe_constantize
    raise "Couldnt find resource from resource name: #{resource_class_name}" unless resource

    resource
  end
end