Class: Contracts::Snapshot

Inherits:
Object
  • Object
show all
Defined in:
lib/contracts.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(values, metadata: {}) ⇒ Snapshot

Returns a new instance of Snapshot.



134
135
136
137
138
# File 'lib/contracts.rb', line 134

def initialize(values, metadata: {})
  @values = values.transform_keys(&:to_sym).freeze
  @metadata = .freeze
  freeze
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *arguments) ⇒ Object



148
# File 'lib/contracts.rb', line 148

def method_missing(name, *arguments) = @values.fetch(name) { super }

Instance Attribute Details

#metadataObject (readonly)

Returns the value of attribute metadata.



132
133
134
# File 'lib/contracts.rb', line 132

def 
  @metadata
end

Instance Method Details

#[](key) ⇒ Object



140
141
# File 'lib/contracts.rb', line 140

def [](key) = @values[key.to_sym]
# Explicit splat parameters keep this compatible with Ruby 3.1

#dig(*arguments) ⇒ Object



147
# File 'lib/contracts.rb', line 147

def dig(*arguments) = @values.dig(*arguments)

#fetch(key, *arguments) ⇒ Object

Explicit splat parameters keep this compatible with Ruby 3.1.



142
# File 'lib/contracts.rb', line 142

def fetch(key, *arguments) = @values.fetch(key.to_sym, *arguments)

#key?(key) ⇒ Boolean

Returns:

  • (Boolean)


144
# File 'lib/contracts.rb', line 144

def key?(key) = @values.key?(key.to_sym)

#keysObject



145
# File 'lib/contracts.rb', line 145

def keys = @values.keys

#respond_to_missing?(name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


149
# File 'lib/contracts.rb', line 149

def respond_to_missing?(name, include_private = false) = @values.key?(name) || super

#to_hObject



143
# File 'lib/contracts.rb', line 143

def to_h = @values.dup

#valuesObject



146
# File 'lib/contracts.rb', line 146

def values = @values.values