Class: UseCase::Context
- Inherits:
-
Object
- Object
- UseCase::Context
- Defined in:
- lib/usecasing/context.rb
Defined Under Namespace
Classes: Errors
Instance Attribute Summary collapse
-
#errors ⇒ Object
Returns the value of attribute errors.
Instance Method Summary collapse
- #failure(key, value) ⇒ Object
-
#initialize(hash = {}) ⇒ Context
constructor
A new instance of Context.
- #method_missing(method, *args, &block) ⇒ Object
- #respond_to?(method) ⇒ Boolean
- #success? ⇒ Boolean
Constructor Details
#initialize(hash = {}) ⇒ Context
Returns a new instance of Context.
36 37 38 39 40 |
# File 'lib/usecasing/context.rb', line 36 def initialize(hash = {}) raise ArgumentError.new('Must be a Hash') unless hash.is_a? ::Hash @values = symbolyze_keys(hash) @errors = Errors.new end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
42 43 44 45 |
# File 'lib/usecasing/context.rb', line 42 def method_missing(method, *args, &block) return @values[extract_key_from(method)] = args.first if setter? method @values[method] end |
Instance Attribute Details
#errors ⇒ Object
Returns the value of attribute errors.
34 35 36 |
# File 'lib/usecasing/context.rb', line 34 def errors @errors end |
Instance Method Details
#failure(key, value) ⇒ Object
55 56 57 |
# File 'lib/usecasing/context.rb', line 55 def failure(key, value) @errors.push(key, value) end |
#respond_to?(method) ⇒ Boolean
47 48 49 |
# File 'lib/usecasing/context.rb', line 47 def respond_to?(method) @values.keys.include?(method.to_sym) end |
#success? ⇒ Boolean
51 52 53 |
# File 'lib/usecasing/context.rb', line 51 def success? @errors.empty? end |