Class: Middleman::CoreExtensions::Data::Stores::InMemoryDataStore

Inherits:
BaseDataStore
  • Object
show all
Extended by:
Forwardable
Includes:
Contracts
Defined in:
middleman-core/lib/middleman-core/core_extensions/data/stores/in_memory.rb

Overview

Static data, passed in via config.rb

Constant Summary

Constants included from Contracts

Contracts::ImmutableSortedSetOf, Contracts::PATH_MATCHER

Instance Method Summary collapse

Methods included from Contracts

#Contract

Methods inherited from BaseDataStore

#[], #key?, #keys, #to_h

Constructor Details

#initializeInMemoryDataStore

Returns a new instance of InMemoryDataStore.


20
21
22
23
24
25
# File 'middleman-core/lib/middleman-core/core_extensions/data/stores/in_memory.rb', line 20

def initialize
  super()

  @sources = {}
  @keys_to_vertex = {}
end

Instance Method Details

#callbacks(name, callback) ⇒ Object


47
48
49
# File 'middleman-core/lib/middleman-core/core_extensions/data/stores/in_memory.rb', line 47

def callbacks(name, callback)
  store(name, callback.call)
end

#store(name, content) ⇒ Object


38
39
40
41
42
43
# File 'middleman-core/lib/middleman-core/core_extensions/data/stores/in_memory.rb', line 38

def store(name, content)
  @sources[name] = content

  @keys_to_vertex[name] = ::Hamster::Set.empty
  @keys_to_vertex[name] <<= ::Middleman::Dependencies::DataCollectionVertex.from_data(name, content)
end

#SymbolHash

Store static data hash

Parameters:

  • name (Symbol)

    Name of the data, used for namespacing

  • content (Hash)

    The content for this data

Returns:

  • (Hash)

37
# File 'middleman-core/lib/middleman-core/core_extensions/data/stores/in_memory.rb', line 37

Contract Symbol, Or[Hash, Array] => Any

#verticesObject


28
29
30
# File 'middleman-core/lib/middleman-core/core_extensions/data/stores/in_memory.rb', line 28

def vertices
  Hamster::Set.new(@keys_to_vertex.values.flatten(1))
end