Class: GoodServices::Base

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

Constant Summary collapse

DEFAULT_RESCUES =
[]

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Class Attribute Details

.default_rescuesObject

Returns the value of attribute default_rescues.



9
10
11
# File 'lib/good_services/base.rb', line 9

def default_rescues
  @default_rescues
end

.rescuable_listObject

Returns the value of attribute rescuable_list.



9
10
11
# File 'lib/good_services/base.rb', line 9

def rescuable_list
  @rescuable_list
end

Instance Attribute Details

#collectionObject (readonly)

Returns the value of attribute collection.



3
4
5
# File 'lib/good_services/base.rb', line 3

def collection
  @collection
end

#errorObject (readonly)

Returns the value of attribute error.



3
4
5
# File 'lib/good_services/base.rb', line 3

def error
  @error
end

#recordObject (readonly)

Returns the value of attribute record.



3
4
5
# File 'lib/good_services/base.rb', line 3

def record
  @record
end

Class Method Details

.acceptable_exceptionsObject

This method returns either the set rescuable_from or the defaults



72
73
74
# File 'lib/good_services/base.rb', line 72

def self.acceptable_exceptions
  (@rescuable_list + @default_rescues).uniq
end

.inherit_variables(rescuable_list, default_rescues) ⇒ Object



13
14
15
16
# File 'lib/good_services/base.rb', line 13

def inherit_variables(rescuable_list, default_rescues)
  @rescuable_list  = rescuable_list  || []
  @default_rescues = default_rescues || DEFAULT_RESCUES
end

.inherited(subclass) ⇒ Object



18
19
20
# File 'lib/good_services/base.rb', line 18

def inherited(subclass)
  subclass.inherit_variables(@rescuable_list, @default_rescues)
end

.rescuable_from(*rescuable_exceptions) ⇒ Object

This configuration method adds custom exceptions to the rescuable list



65
66
67
# File 'lib/good_services/base.rb', line 65

def self.rescuable_from(*rescuable_exceptions)
  @rescuable_list = rescuable_exceptions
end

.run(*args) ⇒ Object

Helpers for instancing and running the Service



26
27
28
# File 'lib/good_services/base.rb', line 26

def self.run(*args)
  self.new(*args).run
end

.run!(*args) ⇒ Object



30
31
32
# File 'lib/good_services/base.rb', line 30

def self.run!(*args)
  self.new(*args).run!
end

Instance Method Details

#performObject



59
60
# File 'lib/good_services/base.rb', line 59

def perform
end

#runObject

Runs the validations and perform methods rescuing from known exceptions Returns either true or false



48
49
50
51
52
53
54
# File 'lib/good_services/base.rb', line 48

def run
  validate
  perform
  return true
rescue *self.class.acceptable_exceptions => @error
  return false
end

#run!Object

Runs the validations and perform methods Returns true or raise an exception



38
39
40
41
42
# File 'lib/good_services/base.rb', line 38

def run!
  validate
  perform
  return true
end

#validateObject



56
57
# File 'lib/good_services/base.rb', line 56

def validate
end