Class: Sequoia::Entity
- Inherits:
-
Struct
- Object
- Struct
- Sequoia::Entity
- 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
-
.create(store = Store.new) ⇒ Object
Factory: Create new instance of entity.
Instance Method Summary collapse
-
#method_missing ⇒ Object
Do not raise exceptions when key not found.
-
#pretty_inspect ⇒ Object
Returns: String a pretty printed object.
-
#to_hash ⇒ Object
Convert content of entity to hash.
-
#to_s ⇒ Object
(also: #inspect)
Represent content of entity as hash string.
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing ⇒ Object
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_inspect ⇒ Object
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_hash ⇒ Object
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_s ⇒ Object 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 |