Class: Shokkenki::Consumer::Stubber::Interaction
- Inherits:
-
Object
- Object
- Shokkenki::Consumer::Stubber::Interaction
- Defined in:
- lib/shokkenki/consumer/stubber/interaction.rb
Instance Attribute Summary collapse
-
#label ⇒ Object
readonly
Returns the value of attribute label.
-
#matched_requests ⇒ Object
readonly
Returns the value of attribute matched_requests.
-
#request ⇒ Object
readonly
Returns the value of attribute request.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
-
#time ⇒ Object
readonly
Returns the value of attribute time.
Class Method Summary collapse
Instance Method Summary collapse
- #add_match(request) ⇒ Object
- #generate_response ⇒ Object
-
#initialize(attributes) ⇒ Interaction
constructor
A new instance of Interaction.
- #match_request?(request) ⇒ Boolean
- #to_hash ⇒ Object
Constructor Details
#initialize(attributes) ⇒ Interaction
Returns a new instance of Interaction.
22 23 24 25 26 27 28 |
# File 'lib/shokkenki/consumer/stubber/interaction.rb', line 22 def initialize attributes @label = attributes[:label] @request = attributes[:request] @response = attributes[:response] @time = attributes[:time] @matched_requests = [] end |
Instance Attribute Details
#label ⇒ Object (readonly)
Returns the value of attribute label.
9 10 11 |
# File 'lib/shokkenki/consumer/stubber/interaction.rb', line 9 def label @label end |
#matched_requests ⇒ Object (readonly)
Returns the value of attribute matched_requests.
9 10 11 |
# File 'lib/shokkenki/consumer/stubber/interaction.rb', line 9 def matched_requests @matched_requests end |
#request ⇒ Object (readonly)
Returns the value of attribute request.
9 10 11 |
# File 'lib/shokkenki/consumer/stubber/interaction.rb', line 9 def request @request end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
9 10 11 |
# File 'lib/shokkenki/consumer/stubber/interaction.rb', line 9 def response @response end |
#time ⇒ Object (readonly)
Returns the value of attribute time.
9 10 11 |
# File 'lib/shokkenki/consumer/stubber/interaction.rb', line 9 def time @time end |
Class Method Details
.from_json(json) ⇒ Object
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/shokkenki/consumer/stubber/interaction.rb', line 11 def self.from_json json attributes = json.with_indifferent_access new( :label => attributes[:label], :request => Shokkenki::Term::TermFactory.from_json(attributes[:request]), :response => Shokkenki::Term::TermFactory.from_json(attributes[:response]), :time => attributes[:time] ) end |
Instance Method Details
#add_match(request) ⇒ Object
44 45 46 47 |
# File 'lib/shokkenki/consumer/stubber/interaction.rb', line 44 def add_match request @matched_requests << request request.interaction = self end |
#generate_response ⇒ Object
36 37 38 |
# File 'lib/shokkenki/consumer/stubber/interaction.rb', line 36 def generate_response @response.example end |
#match_request?(request) ⇒ Boolean
40 41 42 |
# File 'lib/shokkenki/consumer/stubber/interaction.rb', line 40 def match_request? request @request.match? request end |
#to_hash ⇒ Object
30 31 32 33 34 |
# File 'lib/shokkenki/consumer/stubber/interaction.rb', line 30 def to_hash { :label => @label } end |