Class: Olaf::Fake
- Inherits:
-
Object
- Object
- Olaf::Fake
- Defined in:
- lib/olaf/drivers/fake.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#execution_log ⇒ Object
readonly
Returns the value of attribute execution_log.
-
#recorded_responses ⇒ Object
readonly
Returns the value of attribute recorded_responses.
Instance Method Summary collapse
- #fetch(olaf_query) ⇒ Object
-
#initialize(**config) ⇒ Fake
constructor
A new instance of Fake.
- #register_result(olaf_query_class, result, with: :generic) ⇒ Object
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
#config ⇒ Object (readonly)
Returns the value of attribute config.
3 4 5 |
# File 'lib/olaf/drivers/fake.rb', line 3 def config @config end |
#execution_log ⇒ Object (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_responses ⇒ Object (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 |