Class: LazyLazer::KeyMetadataStore

Inherits:
Object
  • Object
show all
Defined in:
lib/lazy_lazer/key_metadata_store.rb

Overview

The key metadata collection class

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeKeyMetadataStore

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_propertiesArray<Symbol> (readonly)

Returns the required properties.

Returns:

  • (Array<Symbol>)

    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.

Parameters:

  • key (Symbol)

    the key

  • meta (KeyMetadata)

    the key metadata

Returns:



25
26
27
28
29
30
31
32
33
# File 'lib/lazy_lazer/key_metadata_store.rb', line 25

def add(key, meta)
  @collection[key] = meta
  if meta.required?
    @required_properties << key
  else
    @required_properties.delete(key)
  end
  meta
end

#contains?(key) ⇒ Boolean

Returns whether the store contains the key.

Returns:

  • (Boolean)

    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.

Returns:



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

#keysArray<Symbol>

Returns the keys in the store.

Returns:

  • (Array<Symbol>)

    the keys in the store



36
37
38
# File 'lib/lazy_lazer/key_metadata_store.rb', line 36

def keys
  @collection.keys
end