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.



92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/flexirest/caching.rb', line 92

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.



90
91
92
# File 'lib/flexirest/caching.rb', line 90

def class_name
  @class_name
end

#etagObject

Returns the value of attribute etag.



90
91
92
# File 'lib/flexirest/caching.rb', line 90

def etag
  @etag
end

#expiresObject

Returns the value of attribute expires.



90
91
92
# File 'lib/flexirest/caching.rb', line 90

def expires
  @expires
end

#response_headersObject

Returns the value of attribute response_headers.



90
91
92
# File 'lib/flexirest/caching.rb', line 90

def response_headers
  @response_headers
end

#statusObject

Returns the value of attribute status.



90
91
92
# File 'lib/flexirest/caching.rb', line 90

def status
  @status
end

Instance Method Details

#resultObject



107
108
109
110
111
112
113
114
115
116
117
# File 'lib/flexirest/caching.rb', line 107

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
  else
    @class_name.constantize.new(@result)
  end
end