Class: Olaf::Fake

Inherits:
Object
  • Object
show all
Defined in:
lib/olaf/drivers/fake.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**config) ⇒ Fake

Returns a new instance of Fake.



5
6
7
8
9
# File 'lib/olaf/drivers/fake.rb', line 5

def initialize(**config)
  @config = config
  @execution_log = []
  @recorded_responses = {}
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



3
4
5
# File 'lib/olaf/drivers/fake.rb', line 3

def config
  @config
end

#execution_logObject (readonly)

Returns the value of attribute execution_log.



3
4
5
# File 'lib/olaf/drivers/fake.rb', line 3

def execution_log
  @execution_log
end

#recorded_responsesObject (readonly)

Returns the value of attribute recorded_responses.



3
4
5
# File 'lib/olaf/drivers/fake.rb', line 3

def recorded_responses
  @recorded_responses
end

Instance Method Details

#fetch(olaf_query) ⇒ Object



11
12
13
14
15
16
17
18
# File 'lib/olaf/drivers/fake.rb', line 11

def fetch(olaf_query)
  @execution_log << olaf_query

  generic_response = @recorded_responses.dig(olaf_query.class, :generic)
  specific_response = @recorded_responses.dig(olaf_query.class, olaf_query.variables)

  specific_response || generic_response || raise_developer_error!(olaf_query)
end

#register_result(olaf_query_class, result, with: :generic) ⇒ Object



20
21
22
23
# File 'lib/olaf/drivers/fake.rb', line 20

def register_result(olaf_query_class, result, with: :generic)
  @recorded_responses[olaf_query_class] ||= {}
  @recorded_responses[olaf_query_class].merge!(with => result)
end