Class: Hmibo::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/hmibo/base.rb

Overview

Base service class that provides common patterns for service objects Inspired by DetectionTek patterns - simple, dependency-free Ruby classes

Direct Known Subclasses

BulkCreation

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Base

Returns a new instance of Base.



9
10
11
12
13
# File 'lib/hmibo/base.rb', line 9

def initialize(*args)
  @errors = []
  @data = nil
  setup(*args) if respond_to?(:setup, true)
end

Instance Attribute Details

#dataObject

Returns the value of attribute data.



7
8
9
# File 'lib/hmibo/base.rb', line 7

def data
  @data
end

#errorsObject

Returns the value of attribute errors.



7
8
9
# File 'lib/hmibo/base.rb', line 7

def errors
  @errors
end

Class Method Details

.call(*args, **kwargs) ⇒ Object

Class method for convenient service execution



24
25
26
# File 'lib/hmibo/base.rb', line 24

def self.call(*args, **kwargs)
  new(*args, **kwargs).call
end

Instance Method Details

#callObject

Main entry point for service execution



16
17
18
19
20
21
# File 'lib/hmibo/base.rb', line 16

def call
  perform
rescue StandardError => e
  handle_error(e)
  self
end

#errors?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/hmibo/base.rb', line 28

def errors?
  !@errors.empty?
end