Class: Flexirest::CachedResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/flexirest/caching.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ CachedResponse

Returns a new instance of CachedResponse.



99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/flexirest/caching.rb', line 99

def initialize(options)
  @status = options[:status]
  @etag = options[:etag]
  @expires = options[:expires]
  @response_headers = options[:response_headers]

  @class_name = options[:result].class.name
  if options[:result].is_a?(ResultIterator)
    @class_name = options[:result][0].class.name
    @result = options[:result].map{|i| {}.merge(i._attributes)}
  else
    @result = {}.merge(options[:result].try(:_attributes) || {})
  end
end

Instance Attribute Details

#class_nameObject

Returns the value of attribute class_name.



97
98
99
# File 'lib/flexirest/caching.rb', line 97

def class_name
  @class_name
end

#etagObject

Returns the value of attribute etag.



97
98
99
# File 'lib/flexirest/caching.rb', line 97

def etag
  @etag
end

#expiresObject

Returns the value of attribute expires.



97
98
99
# File 'lib/flexirest/caching.rb', line 97

def expires
  @expires
end

#response_headersObject

Returns the value of attribute response_headers.



97
98
99
# File 'lib/flexirest/caching.rb', line 97

def response_headers
  @response_headers
end

#statusObject

Returns the value of attribute status.



97
98
99
# File 'lib/flexirest/caching.rb', line 97

def status
  @status
end

Instance Method Details

#resultObject



114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/flexirest/caching.rb', line 114

def result
  return @result if @class_name.nil? # Old cached instance

  if @result.is_a?(Array)
    ri = ResultIterator.new(self)
    ri.items = @result.map{|i| @class_name.constantize.new(i)}
    ri._clean!
    ri
  else
    obj = @class_name.constantize.new(@result)
    obj._clean!
    obj
  end
end