Class: Replicant::Response
- Inherits:
-
Object
- Object
- Replicant::Response
- Defined in:
- lib/replicant/response.rb
Instance Attribute Summary collapse
-
#method ⇒ Object
readonly
Returns the value of attribute method.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #content(post = { }) ⇒ Object
-
#initialize(name, method, path, content) ⇒ Response
constructor
A new instance of Response.
- #requested?(times = 1) ⇒ Boolean
- #requested_via_post?(post_data = { }, times = 1) ⇒ Boolean
- #to_s ⇒ Object
Constructor Details
#initialize(name, method, path, content) ⇒ Response
Returns a new instance of Response.
5 6 7 8 9 10 11 12 |
# File 'lib/replicant/response.rb', line 5 def initialize( name, method, path, content ) @name = name @method = method @path = path @content = content @requests = [ ] end |
Instance Attribute Details
#method ⇒ Object (readonly)
Returns the value of attribute method.
3 4 5 |
# File 'lib/replicant/response.rb', line 3 def method @method end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/replicant/response.rb', line 3 def name @name end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
3 4 5 |
# File 'lib/replicant/response.rb', line 3 def path @path end |
Instance Method Details
#content(post = { }) ⇒ Object
14 15 16 17 |
# File 'lib/replicant/response.rb', line 14 def content( post = { } ) mark_as_requested( post ) @content end |
#requested?(times = 1) ⇒ Boolean
19 20 21 |
# File 'lib/replicant/response.rb', line 19 def requested?( times = 1 ) @requests.length == times end |
#requested_via_post?(post_data = { }, times = 1) ⇒ Boolean
23 24 25 |
# File 'lib/replicant/response.rb', line 23 def requested_via_post?( post_data = { }, times = 1 ) @requests.all? { |request| request[ :post ] == post_data } && requested?( times ) end |
#to_s ⇒ Object
27 28 29 30 31 |
# File 'lib/replicant/response.rb', line 27 def to_s "#{@name} ( #{@path} )\n" + "\tAccessed: #{@requests.length} times\n" + @requests.collect { |request| "\t\t#{request[ :timestamp ]}\n\t\t#{request[ :post ]}\n\n" }.join( "\n" ) end |