Class: HecksApplication::Commands::CRUDHandler

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

Overview

Map resourceful methods to the domain

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(module_name:, application:, validator:) ⇒ CRUDHandler

Returns a new instance of CRUDHandler.



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

def initialize(module_name:, application:, validator:)
  @module_name = module_name
  @application = application
  @validator = validator
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

#validatorObject (readonly)

Returns the value of attribute validator.



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

def validator
  @validator
end

Instance Method Details

#create(args) ⇒ Object



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

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

#delete(id) ⇒ Object



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

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

#read(id) ⇒ Object



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

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

#update(attributes) ⇒ Object



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

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