Class: Invar::Scope

Inherits:
Object
  • Object
show all
Includes:
TestExtension::ScopeMethods
Defined in:
lib/invar/test.rb,
lib/invar/scope.rb

Overview

A set of configurations

Instance Method Summary collapse

Methods included from TestExtension::ScopeMethods

#pretend

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

Parameters:

  • key (symbol)

Raises:

  • KeyError if no such key exists.

See Also:

  • #override


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.message }. Known keys are #{ known_keys }"
end

#key?(key_name) ⇒ Boolean

Returns:

  • (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

Returns:

  • (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_hHash

Returns a hash representation of this scope and subscopes.

Returns:

  • (Hash)

    a hash representation of this scope



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