Class: ServiceResponseDataValues
- Inherits:
-
Object
- Object
- ServiceResponseDataValues
- Defined in:
- app/models/service_response.rb
Overview
A proxy-like class, to provide hash-like access to all arbitrary key/value pairs stored in a ServiceResponse, whether they key/value is stored in an ActiveRecord attribute (#built_in_fields) or in the serialized hash in the service_data attribute. Symbols passed in will be ‘normalized’ to strings before being used as keys. So symbols and strings are interchangeable. Normally, keys should be symbols.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
-
#initialize(arg_service_response) ⇒ ServiceResponseDataValues
constructor
A new instance of ServiceResponseDataValues.
Constructor Details
#initialize(arg_service_response) ⇒ ServiceResponseDataValues
Returns a new instance of ServiceResponseDataValues.
197 198 199 |
# File 'app/models/service_response.rb', line 197 def initialize(arg_service_response) @service_response = arg_service_response end |
Instance Method Details
#[](key) ⇒ Object
201 202 203 204 205 206 207 |
# File 'app/models/service_response.rb', line 201 def [](key) if ServiceResponse.built_in_fields.include?(key) return @service_response.send(key) else return @service_response.service_data[key] end end |
#[]=(key, value) ⇒ Object
209 210 211 212 213 214 215 |
# File 'app/models/service_response.rb', line 209 def []=(key, value) if(ServiceResponse.built_in_fields.include?(key)) @service_response.send(key.to_s+'=', value) else @service_response.service_data[key] = value end end |