Class: Rspec::ApiHelpers::ExampleMethods::ObjectHash
- Inherits:
-
Object
- Object
- Rspec::ApiHelpers::ExampleMethods::ObjectHash
- Defined in:
- lib/rspec/api_helpers/example_methods.rb
Instance Attribute Summary collapse
-
#existing ⇒ Object
existing denotes whether we search for attributes that exist on the resource or attributes that shouldn’t exist.
-
#hash ⇒ Object
existing denotes whether we search for attributes that exist on the resource or attributes that shouldn’t exist.
Instance Method Summary collapse
-
#initialize(hash, existing: true) ⇒ ObjectHash
constructor
A new instance of ObjectHash.
- #method_missing(name) ⇒ Object
Constructor Details
#initialize(hash, existing: true) ⇒ ObjectHash
Returns a new instance of ObjectHash.
40 41 42 43 |
# File 'lib/rspec/api_helpers/example_methods.rb', line 40 def initialize(hash, existing: true) @hash = HashWithIndifferentAccess.new(hash) @existing = existing end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/rspec/api_helpers/example_methods.rb', line 44 def method_missing(name) if existing if hash.key?(name) return hash[name] else return raise KeyError.new("Attribute not found in resource: #{name}") end else if hash.key?(name) return raise( KeyError.new( "Attribute found in resource when it shouldn't: #{name}" ) ) else return :attribute_not_found end end end |
Instance Attribute Details
#existing ⇒ Object
existing denotes whether we search for attributes that exist on the resource or attributes that shouldn’t exist
39 40 41 |
# File 'lib/rspec/api_helpers/example_methods.rb', line 39 def existing @existing end |
#hash ⇒ Object
existing denotes whether we search for attributes that exist on the resource or attributes that shouldn’t exist
39 40 41 |
# File 'lib/rspec/api_helpers/example_methods.rb', line 39 def hash @hash end |