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.



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

def initialize(options)
  @status = options[:status]
  @etag = options[:etag]
  @expires = options[:expires]
  @response_headers = options[:response_headers]
  @old_cached_instance = options[:result].class.name.nil?

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

Instance Attribute Details

#class_nameObject

Returns the value of attribute class_name.



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

def class_name
  @class_name
end

#etagObject

Returns the value of attribute etag.



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

def etag
  @etag
end

#expiresObject

Returns the value of attribute expires.



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

def expires
  @expires
end

#response_headersObject

Returns the value of attribute response_headers.



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

def response_headers
  @response_headers
end

#statusObject

Returns the value of attribute status.



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

def status
  @status
end

Instance Method Details

#resultObject



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

def result
  return @result if @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