Class: Invar::Scope
- Inherits:
-
Object
- Object
- Invar::Scope
- Includes:
- TestExtension::ScopeMethods
- Defined in:
- lib/invar/test.rb,
lib/invar/scope.rb
Overview
A set of configurations
Instance Method Summary collapse
-
#fetch(key) ⇒ Object
(also: #/, #[])
Retrieve the value for the given key.
-
#initialize(data = nil) ⇒ Scope
constructor
A new instance of Scope.
- #key?(key_name) ⇒ Boolean
- #method_missing(method_name, *args) ⇒ Object
- #respond_to_missing?(method_name, include_all) ⇒ Boolean
-
#to_h ⇒ Hash
Returns a hash representation of this scope and subscopes.
Methods included from TestExtension::ScopeMethods
Constructor Details
#initialize(data = nil) ⇒ Scope
Returns a new instance of Scope.
6 7 8 9 10 11 |
# File 'lib/invar/scope.rb', line 6 def initialize(data = nil) @data = convert(data) @data.freeze freeze end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args) ⇒ Object
28 29 30 31 32 |
# File 'lib/invar/scope.rb', line 28 def method_missing(method_name, *args) guard_test_methods method_name super end |
Instance Method Details
#fetch(key) ⇒ Object Also known as: /, []
Retrieve the value for the given key
18 19 20 21 22 23 |
# File 'lib/invar/scope.rb', line 18 def fetch(key) key = key.downcase.to_sym @data.fetch key rescue KeyError => e raise KeyError, "#{ e. }. Known keys are #{ known_keys }" end |
#key?(key_name) ⇒ Boolean
54 55 56 |
# File 'lib/invar/scope.rb', line 54 def key?(key_name) to_h.key?(key_name) end |
#respond_to_missing?(method_name, include_all) ⇒ Boolean
34 35 36 37 38 |
# File 'lib/invar/scope.rb', line 34 def respond_to_missing?(method_name, include_all) guard_test_methods method_name super method_name, include_all end |
#to_h ⇒ Hash
Returns a hash representation of this scope and subscopes.
43 44 45 46 47 48 49 50 51 52 |
# File 'lib/invar/scope.rb', line 43 def to_h @data.to_h.transform_values do |value| case value when Scope value.to_h else value end end end |