Class: UseCase::Context
- Inherits:
-
Object
show all
- Defined in:
- lib/usecasing/context.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(hash = {}) ⇒ Context
Returns a new instance of Context.
7
8
9
10
11
|
# File 'lib/usecasing/context.rb', line 7
def initialize(hash = {})
raise ArgumentError.new('Must be a Hash') unless hash.is_a? ::Hash
@values = symbolyze_keys(hash)
@errors = []
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
13
14
15
16
|
# File 'lib/usecasing/context.rb', line 13
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.
5
6
7
|
# File 'lib/usecasing/context.rb', line 5
def errors
@errors
end
|
Instance Method Details
#failure(key, value) ⇒ Object
26
27
28
|
# File 'lib/usecasing/context.rb', line 26
def failure(key, value)
@errors.push({ key => value })
end
|
#respond_to?(method) ⇒ Boolean
18
19
20
|
# File 'lib/usecasing/context.rb', line 18
def respond_to?(method)
@values.keys.include?(method.to_sym)
end
|
#success? ⇒ Boolean
22
23
24
|
# File 'lib/usecasing/context.rb', line 22
def success?
@errors.empty?
end
|