Class: Adapter::ActiveModel::CommonHelpers::ObjectHash
- Inherits:
-
Object
- Object
- Adapter::ActiveModel::CommonHelpers::ObjectHash
- Defined in:
- lib/rspec/api_helpers/adapter/active_model/common_helpers.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.
30 31 32 33 |
# File 'lib/rspec/api_helpers/adapter/active_model/common_helpers.rb', line 30 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
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/rspec/api_helpers/adapter/active_model/common_helpers.rb', line 35 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
29 30 31 |
# File 'lib/rspec/api_helpers/adapter/active_model/common_helpers.rb', line 29 def existing @existing end |
#hash ⇒ Object
existing denotes whether we search for attributes that exist on the resource or attributes that shouldn’t exist
29 30 31 |
# File 'lib/rspec/api_helpers/adapter/active_model/common_helpers.rb', line 29 def hash @hash end |