class LazyLazer::KeyMetadataStore

The key metadata collection class

Attributes

required_properties[R]

@return [Array<Symbol>] the required properties

Public Class Methods

new() click to toggle source
# File lib/lazy_lazer/key_metadata_store.rb, line 9
def initialize
  @collection = {}
  @required_properties = []
end

Public Instance Methods

add(key, meta) click to toggle source

Add a KeyMetadata to the store. @param key [Symbol] the key @param meta [KeyMetadata] the key metadata @return [KeyMetadata] the provided meta

# 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) click to toggle source

@return [Boolean] whether the store contains the key

# File lib/lazy_lazer/key_metadata_store.rb, line 41
def contains?(key)
  @collection.key?(key)
end
get(key) click to toggle source

@return [KeyMetadata] fetch the metadata from the store

# File lib/lazy_lazer/key_metadata_store.rb, line 46
def get(key)
  @collection.fetch(key)
end
initialize_copy(original) click to toggle source

Used for {Object#dup}.

Calls superclass method
# 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() click to toggle source

@return [Array<Symbol>] the keys in the store

# File lib/lazy_lazer/key_metadata_store.rb, line 36
def keys
  @collection.keys
end