Class: LazyLazer::KeyMetadataStore
- Inherits:
-
Object
- Object
- LazyLazer::KeyMetadataStore
- Defined in:
- lib/lazy_lazer/key_metadata_store.rb
Overview
The key metadata collection class
Instance Attribute Summary collapse
-
#required_properties ⇒ Array<Symbol>
readonly
The required properties.
Instance Method Summary collapse
-
#add(key, meta) ⇒ KeyMetadata
Add a KeyMetadata to the store.
-
#contains?(key) ⇒ Boolean
Whether the store contains the key.
-
#get(key) ⇒ KeyMetadata
Fetch the metadata from the store.
-
#initialize ⇒ KeyMetadataStore
constructor
A new instance of KeyMetadataStore.
-
#initialize_copy(original) ⇒ Object
Used for Object#dup.
-
#keys ⇒ Array<Symbol>
The keys in the store.
Constructor Details
#initialize ⇒ KeyMetadataStore
Returns a new instance of KeyMetadataStore.
9 10 11 12 |
# File 'lib/lazy_lazer/key_metadata_store.rb', line 9 def initialize @collection = {} @required_properties = [] end |
Instance Attribute Details
#required_properties ⇒ Array<Symbol> (readonly)
Returns the required properties.
7 8 9 |
# File 'lib/lazy_lazer/key_metadata_store.rb', line 7 def required_properties @required_properties end |
Instance Method Details
#add(key, meta) ⇒ KeyMetadata
Add a KeyMetadata to the store.
25 26 27 28 29 30 31 32 33 |
# File 'lib/lazy_lazer/key_metadata_store.rb', line 25 def add(key, ) @collection[key] = if .required? @required_properties << key else @required_properties.delete(key) end end |
#contains?(key) ⇒ Boolean
Returns whether the store contains the key.
41 42 43 |
# File 'lib/lazy_lazer/key_metadata_store.rb', line 41 def contains?(key) @collection.key?(key) end |
#get(key) ⇒ KeyMetadata
Returns fetch the metadata from the store.
46 47 48 |
# File 'lib/lazy_lazer/key_metadata_store.rb', line 46 def get(key) @collection.fetch(key) end |
#initialize_copy(original) ⇒ Object
Used for Object#dup.
15 16 17 18 19 |
# File 'lib/lazy_lazer/key_metadata_store.rb', line 15 def initialize_copy(original) super @collection = original.instance_variable_get(:@collection).dup @required_properties = original.instance_variable_get(:@required_properties).dup end |
#keys ⇒ Array<Symbol>
Returns the keys in the store.
36 37 38 |
# File 'lib/lazy_lazer/key_metadata_store.rb', line 36 def keys @collection.keys end |