Class: Shokkenki::Consumer::Stubber::Interaction

Inherits:
Object
  • Object
show all
Defined in:
lib/shokkenki/consumer/stubber/interaction.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#labelObject (readonly)

Returns the value of attribute label.



9
10
11
# File 'lib/shokkenki/consumer/stubber/interaction.rb', line 9

def label
  @label
end

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

#requestObject (readonly)

Returns the value of attribute request.



9
10
11
# File 'lib/shokkenki/consumer/stubber/interaction.rb', line 9

def request
  @request
end

#responseObject (readonly)

Returns the value of attribute response.



9
10
11
# File 'lib/shokkenki/consumer/stubber/interaction.rb', line 9

def response
  @response
end

#timeObject (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_responseObject



36
37
38
# File 'lib/shokkenki/consumer/stubber/interaction.rb', line 36

def generate_response
  @response.example
end

#match_request?(request) ⇒ Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/shokkenki/consumer/stubber/interaction.rb', line 40

def match_request? request
  @request.match? request
end

#to_hashObject



30
31
32
33
34
# File 'lib/shokkenki/consumer/stubber/interaction.rb', line 30

def to_hash
  {
    :label => @label
  }
end