Class: GlobalCollect::RequestModels::Base
- Inherits:
-
Object
- Object
- GlobalCollect::RequestModels::Base
show all
- Defined in:
- lib/global_collect/request_models/base.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(attributes) ⇒ Base
Returns a new instance of Base.
12
13
14
15
|
# File 'lib/global_collect/request_models/base.rb', line 12
def initialize(attributes)
@attributes = {}
attributes.each {|k,v| self[k] = v }
end
|
Instance Attribute Details
#errors ⇒ Object
Returns the value of attribute errors.
3
4
5
|
# File 'lib/global_collect/request_models/base.rb', line 3
def errors
@errors
end
|
Instance Method Details
#[](key) ⇒ Object
27
28
29
30
|
# File 'lib/global_collect/request_models/base.rb', line 27
def [](key)
raise ArgumentError.new("Invalid attribute name '#{key}'!") unless fields.key?(key)
@attributes[key]
end
|
#[]=(key, value) ⇒ Object
32
33
34
35
|
# File 'lib/global_collect/request_models/base.rb', line 32
def []=(key, value)
raise ArgumentError.new("Invalid attribute name '#{key}'!") unless fields.key?(key)
@attributes[key] = value
end
|
#fields ⇒ Object
8
9
10
|
# File 'lib/global_collect/request_models/base.rb', line 8
def fields
{}
end
|
#suggested_response_mixins ⇒ Object
4
5
6
|
# File 'lib/global_collect/request_models/base.rb', line 4
def suggested_response_mixins
[]
end
|
#validate ⇒ Object
17
18
19
20
21
22
23
24
25
|
# File 'lib/global_collect/request_models/base.rb', line 17
def validate
fields.each do |field, validations|
validator = GlobalCollect::FieldValidator.new(*validations)
unless validator.validate(@attributes[field])
@errors = { field => "is invalid. Should conform to #{validations.inspect}" }
end
end
return @errors.blank?
end
|