Class: Sequoia::Entity

Inherits:
Struct
  • Object
show all
Defined in:
lib/sequoia/entity.rb

Overview

Class: Resulting storage of configuration data

Once it initialized - it can’t be modified

Class Method Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missingObject

Do not raise exceptions when key not found



60
61
62
# File 'lib/sequoia/entity.rb', line 60

def method_missing(*)
  return nil
end

Class Method Details

.create(store = Store.new) ⇒ Object

Factory: Create new instance of entity

Returns: Sequoia::Entity



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/sequoia/entity.rb', line 16

def self.create(store=Store.new)
  keys = store.keys

  values = store.values.map do |value|
    value.class == Store ? create(value) : value
  end

  if keys.any?
    new(*keys).new(*values).freeze
  else
    Object.new.freeze
  end
end

Instance Method Details

#pretty_inspectObject

Returns: String a pretty printed object



54
55
56
# File 'lib/sequoia/entity.rb', line 54

def pretty_inspect
  PP.pp(to_hash, '')
end

#to_hashObject

Convert content of entity to hash

TODO: Deep #to_hash

Returns: Hash Hash of all keys and values



37
38
39
# File 'lib/sequoia/entity.rb', line 37

def to_hash
  members.each_with_object({}) { |key, obj| obj[key] = self[key] }
end

#to_sObject Also known as: inspect

Represent content of entity as hash string

Returns: String String with keys and values in hash format



46
47
48
# File 'lib/sequoia/entity.rb', line 46

def to_s
  to_hash.to_s
end