Class: Replicant::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/replicant/response.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#methodObject (readonly)

Returns the value of attribute method.



3
4
5
# File 'lib/replicant/response.rb', line 3

def method
  @method
end

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/replicant/response.rb', line 3

def name
  @name
end

#pathObject (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

Returns:

  • (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

Returns:

  • (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_sObject



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