Module: Cushion::Meta

Defined in:
lib/cushion.rb

Overview

Provides a clean method of adding metadata (e.g., headers) to JSON parsed responses. Inspired by OpenURI::Meta.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#headersObject

Returns the value of attribute headers.



130
131
132
# File 'lib/cushion.rb', line 130

def headers
  @headers
end

Class Method Details

.init(obj, src = nil) ⇒ Object



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

def Meta.init(obj, src=nil)
  obj.extend Meta
  obj.instance_eval {
    @headers = {}
  }
  if src
    src.headers.each {|name, value|
      obj.add_header_field(name, value)
    }
  end
  obj
end

Instance Method Details

#add_header_field(name, value) ⇒ Object



132
133
134
135
# File 'lib/cushion.rb', line 132

def add_header_field(name, value)
  #value.gsub!('"', '') if name == :etag  ==> CouchDB seems to require the xtra "'s
  @headers[name] = value
end

#etagObject



137
138
139
# File 'lib/cushion.rb', line 137

def etag
  @headers[:etag]
end