Module: DbStore

Defined in:
lib/wherever/db_store.rb,
lib/wherever/db_store.rb,
lib/wherever/db_store/lookup.rb,
lib/wherever/db_store/dataset.rb,
lib/wherever/db_store/identifier.rb,
lib/wherever/db_store/record_matcher.rb

Defined Under Namespace

Modules: DatasetConfig, IdentifierConfig, RecordMatcher, VersionConfig Classes: Container, Dataset, Identifier, Lookup, Version

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.storesObject (readonly)

Returns the value of attribute stores.



12
13
14
# File 'lib/wherever/db_store.rb', line 12

def stores
  @stores
end

Class Method Details

.build_class(name, module_object, store_in) ⇒ Object



40
41
42
43
44
45
# File 'lib/wherever/db_store.rb', line 40

def build_class(name, module_object, store_in)
  klass = DbStore.const_set(name, Class.new)
  klass.send :include, module_object
  klass.send :store_in, store_in
  klass
end

.get_lookup(name, keys) ⇒ Object



32
33
34
35
36
37
38
# File 'lib/wherever/db_store.rb', line 32

def get_lookup(name, keys)
  DbStore::Lookup.find_or_create_by(:name => name, :keys => keys) if keys
  class_name = "Lookup#{name.titlecase}"
  return "DbStore::#{class_name}".constantize if DbStore.constants.include?(class_name)
  raise "Missing lookup key from definition" unless keys
  build_class(class_name, DbStore::VersionConfig, :"lookup_#{name}")
end

.get_store(marker, keys, db_type) ⇒ Object



26
27
28
29
30
# File 'lib/wherever/db_store.rb', line 26

def get_store(marker, keys, db_type)
  name = "#{marker.upcase}_#{keys.map(&:upcase).join('_')}_#{db_type.to_s.upcase}"
  return "DbStore::#{name}".constantize if DbStore.constants.include?(name)
  build_class(name, "DbStore::#{db_type.to_s.titlecase}Config".constantize, :"#{marker}_#{keys.join('_')}_#{db_type}")
end

.new_lookup(name, keys = nil) ⇒ Object



21
22
23
24
# File 'lib/wherever/db_store.rb', line 21

def new_lookup(name, keys=nil)
  @stores ||= {}
  @stores[name] = get_lookup(name, keys)
end

.new_store(marker, keys) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/wherever/db_store.rb', line 13

def new_store(marker, keys)
  @stores ||= {}
  @stores[[marker, keys]] = Container.new(
      get_store(marker, keys, :identifier),
      get_store(marker, keys, :dataset)
  )
end