Class: Nylas::Registry

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/nylas/registry.rb

Overview

Used to create a hash-like structure which defaults to raising an exception in the event the key to retrieve does not exist.

Defined Under Namespace

Classes: MissingKeyError

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(initial_data = {}) ⇒ Registry

Returns a new instance of Registry.



22
23
24
25
26
# File 'lib/nylas/registry.rb', line 22

def initialize(initial_data = {})
  self.registry_data = initial_data.each.each_with_object({}) do |(key, value), registry|
    registry[key] = value
  end
end

Instance Attribute Details

#registry_dataObject

Returns the value of attribute registry_data.



17
18
19
# File 'lib/nylas/registry.rb', line 17

def registry_data
  @registry_data
end

Instance Method Details

#[](key) ⇒ Object



28
29
30
31
32
# File 'lib/nylas/registry.rb', line 28

def [](key)
  registry_data.fetch(key)
rescue KeyError
  raise MissingKeyError.new(key, keys)
end

#[]=(key, value) ⇒ Object



34
35
36
# File 'lib/nylas/registry.rb', line 34

def []=(key, value)
  registry_data[key] = value
end

#to_hObject



38
39
40
# File 'lib/nylas/registry.rb', line 38

def to_h
  registry_data
end