Class: Twterm::AbstractPersistableConfiguration Abstract
- Inherits:
-
Object
- Object
- Twterm::AbstractPersistableConfiguration
- Defined in:
- lib/twterm/abstract_persistable_configuration.rb
Overview
This class is abstract.
Direct Known Subclasses
Class Method Summary collapse
-
.default ⇒ Object
abstract
Returns the default instance for the configuration.
- .has_same_structure? ⇒ Boolean
-
.structure ⇒ Hash
abstract
A tree-like object representing the structure of the configuration.
Instance Method Summary collapse
-
#[] ⇒ Object
abstract
Gets a value associated to the given key.
-
#[]= ⇒ Object
abstract
Sets the given value to the given key.
- #complete_missing_items! ⇒ self
-
#initialize(configuration = {}) ⇒ AbstractPersistableConfiguration
constructor
A new instance of AbstractPersistableConfiguration.
-
#to_h ⇒ Hash
abstract
Converts to a hash object.
Constructor Details
#initialize(configuration = {}) ⇒ AbstractPersistableConfiguration
Returns a new instance of AbstractPersistableConfiguration.
5 6 7 |
# File 'lib/twterm/abstract_persistable_configuration.rb', line 5 def initialize(configuration = {}) @configuration = configuration end |
Class Method Details
.default ⇒ Object
This method is abstract.
Returns the default instance for the configuration.
23 24 25 |
# File 'lib/twterm/abstract_persistable_configuration.rb', line 23 def self.default raise NotImplementedError, '`.default` method must be implemented' end |
.has_same_structure? ⇒ Boolean
28 29 30 |
# File 'lib/twterm/abstract_persistable_configuration.rb', line 28 def self.has_same_structure? true end |
.structure ⇒ Hash
This method is abstract.
A tree-like object representing the structure of the configuration. Each node must respond to #=== method which determines whether a value is acceptable.
58 59 60 |
# File 'lib/twterm/abstract_persistable_configuration.rb', line 58 def self.structure raise NotImplementedError, '`.structure` method must be implemented' end |
Instance Method Details
#[] ⇒ Object
This method is abstract.
Gets a value associated to the given key.
11 12 13 |
# File 'lib/twterm/abstract_persistable_configuration.rb', line 11 def [](*) raise NotImplementedError, '`#[]` method must be implemented' end |
#[]= ⇒ Object
This method is abstract.
Sets the given value to the given key.
17 18 19 |
# File 'lib/twterm/abstract_persistable_configuration.rb', line 17 def []=(*) raise NotImplementedError, '`#[]=` method must be implemented' end |
#complete_missing_items! ⇒ self
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/twterm/abstract_persistable_configuration.rb', line 33 def complete_missing_items! traverse(self.class.default.to_h) do |path, default_value| value = dig(configuration, path) if value.nil? || !(dig!(self.class.structure, path) === value) bury!(path, default_value) end end self end |
#to_h ⇒ Hash
This method is abstract.
Converts to a hash object.
49 50 51 |
# File 'lib/twterm/abstract_persistable_configuration.rb', line 49 def to_h raise NotImplementedError, '`#to_h` method must be implemented' end |