Class: Flexirest::CachedResponse
- Inherits:
-
Object
- Object
- Flexirest::CachedResponse
- Defined in:
- lib/flexirest/caching.rb
Instance Attribute Summary collapse
-
#class_name ⇒ Object
Returns the value of attribute class_name.
-
#etag ⇒ Object
Returns the value of attribute etag.
-
#expires ⇒ Object
Returns the value of attribute expires.
-
#response_headers ⇒ Object
Returns the value of attribute response_headers.
-
#status ⇒ Object
Returns the value of attribute status.
Instance Method Summary collapse
-
#initialize(options) ⇒ CachedResponse
constructor
A new instance of CachedResponse.
- #result ⇒ Object
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() @status = [:status] @etag = [:etag] @expires = [:expires] @response_headers = [:response_headers] @class_name = [:result].class.name if [:result].is_a?(ResultIterator) @class_name = [:result][0].class.name @result = [:result].map{|i| {}.merge(i._attributes)} else @result = {}.merge([:result].try(:_attributes) || {}) end end |
Instance Attribute Details
#class_name ⇒ Object
Returns the value of attribute class_name.
90 91 92 |
# File 'lib/flexirest/caching.rb', line 90 def class_name @class_name end |
#etag ⇒ Object
Returns the value of attribute etag.
90 91 92 |
# File 'lib/flexirest/caching.rb', line 90 def etag @etag end |
#expires ⇒ Object
Returns the value of attribute expires.
90 91 92 |
# File 'lib/flexirest/caching.rb', line 90 def expires @expires end |
#response_headers ⇒ Object
Returns the value of attribute response_headers.
90 91 92 |
# File 'lib/flexirest/caching.rb', line 90 def response_headers @response_headers end |
#status ⇒ Object
Returns the value of attribute status.
90 91 92 |
# File 'lib/flexirest/caching.rb', line 90 def status @status end |
Instance Method Details
#result ⇒ Object
107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# 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._clean! ri else obj = @class_name.constantize.new(@result) obj._clean! obj end end |