Class: Hecks::Application::Commands::CRUDHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/commands/crud_handler.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(module_name:, application:) ⇒ CRUDHandler

Returns a new instance of CRUDHandler.



7
8
9
10
# File 'lib/commands/crud_handler.rb', line 7

def initialize(module_name:, application:)
  @module_name = module_name
  @application = application
end

Instance Attribute Details

#applicationObject (readonly)

Returns the value of attribute application.



5
6
7
# File 'lib/commands/crud_handler.rb', line 5

def application
  @application
end

#module_nameObject (readonly)

Returns the value of attribute module_name.



5
6
7
# File 'lib/commands/crud_handler.rb', line 5

def module_name
  @module_name
end

Instance Method Details

#create(attributes) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/commands/crud_handler.rb', line 12

def create(attributes)
  application.call(
    module_name: module_name,
    command_name: :create,
    args: attributes
  )
end

#delete(id) ⇒ Object



36
37
38
39
40
41
42
# File 'lib/commands/crud_handler.rb', line 36

def delete(id)
  application.call(
    module_name: module_name,
    command_name: :delete,
    args: { id: id }
  )
end

#read(id) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/commands/crud_handler.rb', line 20

def read(id)
  application.query(
    module_name: module_name,
    query_name: :find_by_id,
    args: { id: id }
  )
end

#update(id, attributes) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/commands/crud_handler.rb', line 28

def update(id, attributes)
  application.call(
    module_name: module_name,
    command_name: :update,
    args: attributes.merge(id: id)
  )
end