Class: ApplicationService

Inherits:
Object
  • Object
show all
Defined in:
lib/generators/service/install/templates/services/application_service.rb

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.bmObject (readonly)

Returns the value of attribute bm.



5
6
7
# File 'lib/generators/service/install/templates/services/application_service.rb', line 5

def bm
  @bm
end

.cmdObject (readonly)

Returns the value of attribute cmd.



5
6
7
# File 'lib/generators/service/install/templates/services/application_service.rb', line 5

def cmd
  @cmd
end

.resultObject (readonly)

Returns the value of attribute result.



5
6
7
# File 'lib/generators/service/install/templates/services/application_service.rb', line 5

def result
  @result
end

.usecaseObject (readonly)

Returns the value of attribute usecase.



5
6
7
# File 'lib/generators/service/install/templates/services/application_service.rb', line 5

def usecase
  @usecase
end

Class Method Details

.call(cmd) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/generators/service/install/templates/services/application_service.rb', line 7

def call(cmd)
  @cmd = cmd
  @bm = Benchmark.measure do
    raise Errors::InvalidCommand if cmd.invalid?

    @usecase = usecase_class.new(cmd)

    raise Errors::NotAuthorizedError unless usecase.allowed?

    @result = ServiceResult.new { usecase.call }

    rollback if result.error.present?
    usecase.broadcast if result.ok?
  end

  log_command
  result
rescue StandardError => e
  ServiceResult.new { raise e }
end

.rollbackObject



28
29
30
31
# File 'lib/generators/service/install/templates/services/application_service.rb', line 28

def rollback
  usecase.rollback_micros
  usecase.rollback
end