Class: ServiceResponseDataValues

Inherits:
Object
  • Object
show all
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

Constructor Details

#initialize(arg_service_response) ⇒ ServiceResponseDataValues

Returns a new instance of ServiceResponseDataValues.



176
177
178
# File 'app/models/service_response.rb', line 176

def initialize(arg_service_response)
  @service_response = arg_service_response
end

Instance Method Details

#[](key) ⇒ Object



180
181
182
183
184
185
186
# File 'app/models/service_response.rb', line 180

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



188
189
190
191
192
193
194
# File 'app/models/service_response.rb', line 188

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