Class: UseCase::Context
- Inherits:
-
Object
show all
- Defined in:
- lib/usecasing/context.rb
Defined Under Namespace
Classes: Errors
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(param = {}) ⇒ Context
Returns a new instance of Context.
36
37
38
39
40
|
# File 'lib/usecasing/context.rb', line 36
def initialize(param = {})
raise ArgumentError.new('Must be a Hash or other Context') unless (param.is_a? ::Hash) || (param.is_a? Context)
@values = symbolyze_keys(param.to_hash)
@errors = Errors.new
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
46
47
48
49
|
# File 'lib/usecasing/context.rb', line 46
def method_missing(method, *args, &block)
return @values[(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
59
60
61
|
# File 'lib/usecasing/context.rb', line 59
def failure(key, value)
@errors.push(key, value)
end
|
#respond_to?(method) ⇒ Boolean
51
52
53
|
# File 'lib/usecasing/context.rb', line 51
def respond_to?(method)
@values.keys.include?(method.to_sym)
end
|
#success? ⇒ Boolean
55
56
57
|
# File 'lib/usecasing/context.rb', line 55
def success?
@errors.empty?
end
|
#to_hash ⇒ Object
42
43
44
|
# File 'lib/usecasing/context.rb', line 42
def to_hash
@values
end
|