Class: Web::Faker
- Inherits:
-
Object
- Object
- Web::Faker
- Defined in:
- lib/web/faker.rb
Overview
A class for representing one faked response
Instance Attribute Summary collapse
-
#cache ⇒ Object
readonly
Returns the value of attribute cache.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
Instance Method Summary collapse
-
#desired? ⇒ Boolean
whether or not this is a key we want.
-
#initialize(method, url, body, headers) ⇒ Faker
constructor
A new instance of Faker.
-
#record(code, body, headers) ⇒ Object
Given a response, marshall down and record in redis.
-
#response_for ⇒ Object
Get the mashalled form from redis and reconstruct into a Web::Response.
Constructor Details
Instance Attribute Details
#cache ⇒ Object (readonly)
Returns the value of attribute cache.
8 9 10 |
# File 'lib/web/faker.rb', line 8 def cache @cache end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
8 9 10 |
# File 'lib/web/faker.rb', line 8 def key @key end |
Instance Method Details
#desired? ⇒ Boolean
whether or not this is a key we want
18 19 20 21 22 |
# File 'lib/web/faker.rb', line 18 def desired? @match = Web.registered.detect do |opt| opt[:regex] =~ @url end end |
#record(code, body, headers) ⇒ Object
Given a response, marshall down and record in redis
25 26 27 28 29 30 31 32 |
# File 'lib/web/faker.rb', line 25 def record(code, body, headers) # save and return the response res = Web::Response.new code, body, headers # Allow expireation to be set expires = @match.has_key?(:expire) ? @match[:expire].to_i : nil cache.set(key, res.dump, expires) res end |