Class: RestMyCase::Base
Instance Attribute Summary collapse
Attributes included from Config::Base
#parent_dependencies_first, #silence_dependencies_abort
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(context, dependent_use_case = nil) ⇒ Base
Returns a new instance of Base.
53
54
55
56
57
|
# File 'lib/rest_my_case/base.rb', line 53
def initialize(context, dependent_use_case = nil)
@options = {}
@context = context
@dependent_use_case = dependent_use_case
end
|
Instance Attribute Details
#context ⇒ Object
INSTANCE METHODS BELLOW ###########################
51
52
53
|
# File 'lib/rest_my_case/base.rb', line 51
def context
@context
end
|
#dependent_use_case ⇒ Object
INSTANCE METHODS BELLOW ###########################
51
52
53
|
# File 'lib/rest_my_case/base.rb', line 51
def dependent_use_case
@dependent_use_case
end
|
#options ⇒ Object
INSTANCE METHODS BELLOW ###########################
51
52
53
|
# File 'lib/rest_my_case/base.rb', line 51
def options
@options
end
|
Class Method Details
.context_accessor(*methods) ⇒ Object
34
35
36
37
|
# File 'lib/rest_my_case/base.rb', line 34
def self.context_accessor(*methods)
context_writer(*methods)
context_reader(*methods)
end
|
.context_reader(*methods) ⇒ Object
45
46
47
|
# File 'lib/rest_my_case/base.rb', line 45
def self.context_reader(*methods)
methods.each { |method| define_method(method) { context.send(method) } }
end
|
.context_writer(*methods) ⇒ Object
39
40
41
42
43
|
# File 'lib/rest_my_case/base.rb', line 39
def self.context_writer(*methods)
methods.each do |method|
define_method("#{method}=") { |value| context.send "#{method}=", value }
end
end
|
.dependencies ⇒ Object
20
21
22
|
# File 'lib/rest_my_case/base.rb', line 20
def self.dependencies
@dependencies ||= []
end
|
.depends(*use_case_classes) ⇒ Object
16
17
18
|
# File 'lib/rest_my_case/base.rb', line 16
def self.depends(*use_case_classes)
dependencies.push(*use_case_classes)
end
|
24
25
26
27
28
29
30
31
32
|
# File 'lib/rest_my_case/base.rb', line 24
def self.perform(attributes = nil)
attributes ||= {}
unless attributes.respond_to?(:to_hash)
fail ArgumentError, 'Must respond_to method #to_hash'
end
trial_court.execute([self], attributes.to_hash).context
end
|
.trial_court ⇒ Object
7
8
9
10
|
# File 'lib/rest_my_case/base.rb', line 7
def self.trial_court
@trial_court ||= Trial::Court.new \
Judge::Base, DefenseAttorney::Base, RestMyCase::Base, Context::Base
end
|
.trial_court=(new_trial_court) ⇒ Object
12
13
14
|
# File 'lib/rest_my_case/base.rb', line 12
def self.trial_court=(new_trial_court)
@trial_court = new_trial_court
end
|
Instance Method Details
#abort ⇒ Object
77
78
79
|
# File 'lib/rest_my_case/base.rb', line 77
def abort
silent_abort? ? dependent_use_case.abort : (options[:should_abort] = true)
end
|
#abort! ⇒ Object
81
82
83
|
# File 'lib/rest_my_case/base.rb', line 81
def abort!
abort && fail(Errors::Abort)
end
|
#error(error_data = '') ⇒ Object
85
86
87
88
89
90
91
|
# File 'lib/rest_my_case/base.rb', line 85
def error(error_data = '')
error_data = { message: error_data } unless error_data.is_a?(Hash)
error_data[:class_name] = self.class.name
abort && context.errors.add(error_data)
end
|
#error!(error_data = '') ⇒ Object
93
94
95
|
# File 'lib/rest_my_case/base.rb', line 93
def error!(error_data = '')
error(error_data) && fail(Errors::Abort)
end
|
#final ⇒ Object
65
|
# File 'lib/rest_my_case/base.rb', line 65
def final; end
|
#invoke(*use_case_classes) ⇒ Object
67
68
69
|
# File 'lib/rest_my_case/base.rb', line 67
def invoke(*use_case_classes)
trial_court.execute(use_case_classes, context.to_hash).context
end
|
#invoke!(*use_case_classes) ⇒ Object
71
72
73
74
75
|
# File 'lib/rest_my_case/base.rb', line 71
def invoke!(*use_case_classes)
trial_court.execute(use_case_classes, context).tap do |trial_case|
abort if trial_case.aborted
end.context
end
|
61
|
# File 'lib/rest_my_case/base.rb', line 61
def perform; end
|
#rollback ⇒ Object
63
|
# File 'lib/rest_my_case/base.rb', line 63
def rollback; end
|
#setup ⇒ Object
59
|
# File 'lib/rest_my_case/base.rb', line 59
def setup; end
|
#skip ⇒ Object
97
98
99
|
# File 'lib/rest_my_case/base.rb', line 97
def skip
options[:should_skip] = true
end
|
#skip! ⇒ Object
101
102
103
|
# File 'lib/rest_my_case/base.rb', line 101
def skip!
skip && fail(Errors::Skip)
end
|