Class: RuleBox::Facade
- Inherits:
-
Object
- Object
- RuleBox::Facade
- Includes:
- ExecutionHook, MethodHelper
- Defined in:
- lib/rule_box/facade.rb
Instance Attribute Summary collapse
-
#bucket ⇒ Object
readonly
Returns the value of attribute bucket.
-
#current_method ⇒ Object
readonly
Returns the value of attribute current_method.
-
#current_strategy ⇒ Object
readonly
Returns the value of attribute current_strategy.
-
#entity ⇒ Object
readonly
Returns the value of attribute entity.
-
#exception ⇒ Object
readonly
Returns the value of attribute exception.
-
#executed ⇒ Object
readonly
Returns the value of attribute executed.
-
#last_result ⇒ Object
readonly
Returns the value of attribute last_result.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
-
#strategies ⇒ Object
readonly
Returns the value of attribute strategies.
Class Method Summary collapse
- .add_dependency(key, &block) ⇒ Object
- .clear_configuration! ⇒ Object
- .configure(&block) ⇒ Object
- .set_dependencies(facade, dependencies) ⇒ Object
- .use_case! ⇒ Object
Instance Method Summary collapse
- #add_error(msg) ⇒ Object
- #exec(method = :perform, entity, **args) ⇒ Object
- #get(key) ⇒ Object
-
#initialize(**dependencies) ⇒ Facade
constructor
A new instance of Facade.
- #instance_values ⇒ Object
- #run ⇒ Object
- #set_status(status) ⇒ Object
Methods included from ExecutionHook
Methods included from MethodHelper
Constructor Details
#initialize(**dependencies) ⇒ Facade
Returns a new instance of Facade.
13 14 15 16 |
# File 'lib/rule_box/facade.rb', line 13 def initialize(**dependencies) set_dependencies! dependencies @executed = false end |
Instance Attribute Details
#bucket ⇒ Object (readonly)
Returns the value of attribute bucket.
8 9 10 |
# File 'lib/rule_box/facade.rb', line 8 def bucket @bucket end |
#current_method ⇒ Object (readonly)
Returns the value of attribute current_method.
8 9 10 |
# File 'lib/rule_box/facade.rb', line 8 def current_method @current_method end |
#current_strategy ⇒ Object (readonly)
Returns the value of attribute current_strategy.
8 9 10 |
# File 'lib/rule_box/facade.rb', line 8 def current_strategy @current_strategy end |
#entity ⇒ Object (readonly)
Returns the value of attribute entity.
8 9 10 |
# File 'lib/rule_box/facade.rb', line 8 def entity @entity end |
#exception ⇒ Object (readonly)
Returns the value of attribute exception.
8 9 10 |
# File 'lib/rule_box/facade.rb', line 8 def exception @exception end |
#executed ⇒ Object (readonly)
Returns the value of attribute executed.
8 9 10 |
# File 'lib/rule_box/facade.rb', line 8 def executed @executed end |
#last_result ⇒ Object (readonly)
Returns the value of attribute last_result.
8 9 10 |
# File 'lib/rule_box/facade.rb', line 8 def last_result @last_result end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
8 9 10 |
# File 'lib/rule_box/facade.rb', line 8 def status @status end |
#strategies ⇒ Object (readonly)
Returns the value of attribute strategies.
8 9 10 |
# File 'lib/rule_box/facade.rb', line 8 def strategies @strategies end |
Class Method Details
.add_dependency(key, &block) ⇒ Object
216 217 218 |
# File 'lib/rule_box/facade.rb', line 216 def add_dependency(key, &block) dependencies[key.to_sym] = block end |
.clear_configuration! ⇒ Object
224 225 226 227 |
# File 'lib/rule_box/facade.rb', line 224 def clear_configuration! @dependencies = {} clear_hooks! end |
.configure(&block) ⇒ Object
220 221 222 |
# File 'lib/rule_box/facade.rb', line 220 def configure(&block) block.call(self) end |
.set_dependencies(facade, dependencies) ⇒ Object
229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 |
# File 'lib/rule_box/facade.rb', line 229 def set_dependencies(facade, dependencies) errors = [] self.dependencies.each do |key, block| if dependencies.key? key value = dependencies[key] block&.call(value, errors) facade.send(:set, key, value) else errors << "missing keyword: #{key}" end rescue StandardError => e errors << e. end raise errors.join("\n") unless errors.empty? end |
.use_case! ⇒ Object
247 248 249 |
# File 'lib/rule_box/facade.rb', line 247 def use_case! define_method(:use_case) { entity } end |
Instance Method Details
#add_error(msg) ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/rule_box/facade.rb', line 18 def add_error(msg) if msg.is_a? Array msg.each { || add_error() } else @errors << msg end end |
#exec(method = :perform, entity, **args) ⇒ Object
26 27 28 |
# File 'lib/rule_box/facade.rb', line 26 def exec(method = :perform, entity, **args) perform method, entity, **args end |
#get(key) ⇒ Object
30 31 32 |
# File 'lib/rule_box/facade.rb', line 30 def get(key) keys[key.to_s].clone end |
#instance_values ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/rule_box/facade.rb', line 45 def instance_values hash = { current_strategy: @current_strategy&.instance_values, strategies: (@strategies || []).map(&:instance_values) } keys.each { |k, v| hash[k.to_sym] = v.clone } i[ entity exception current_class current_method bucket executed last_result status errors steps ].each { |key| hash[key] = send(key).clone } hash end |
#run ⇒ Object
34 35 36 37 38 39 |
# File 'lib/rule_box/facade.rb', line 34 def run return unless @next_run send @next_run true end |
#set_status(status) ⇒ Object
41 42 43 |
# File 'lib/rule_box/facade.rb', line 41 def set_status(status) @status = status end |