Class: Terrestrial::Configurations::ConventionalConfiguration

Inherits:
Object
  • Object
show all
Includes:
Enumerable, Fetchable
Defined in:
lib/terrestrial/configurations/conventional_configuration.rb

Defined Under Namespace

Classes: ArbitraryDatabaseDefaultValueObserver, ArbitraryDatabaseOwnedValueObserver, ClassFactory, DatabaseIDObserver, HashCoercionSerializer, LazyClassLookupFactory, SetterMethodCaller, TableNameNotSpecifiedError, TimestampObserver

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(datastore:, clock:, dirty_map:, identity_map:, inflector: Inflector.new) ⇒ ConventionalConfiguration

Returns a new instance of ConventionalConfiguration.



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/terrestrial/configurations/conventional_configuration.rb', line 30

def initialize(datastore:, clock:, dirty_map:, identity_map:, inflector: Inflector.new)
  @datastore = datastore
  @inflector = inflector
  @dirty_map = dirty_map
  @identity_map = identity_map
  @clock = clock

  @overrides = {}
  @subset_queries = {}
  @associations_by_mapping = {}
end

Instance Attribute Details

#clockObject (readonly)

Returns the value of attribute clock.



42
43
44
# File 'lib/terrestrial/configurations/conventional_configuration.rb', line 42

def clock
  @clock
end

#datastoreObject (readonly)

Returns the value of attribute datastore.



42
43
44
# File 'lib/terrestrial/configurations/conventional_configuration.rb', line 42

def datastore
  @datastore
end

#dirty_mapObject (readonly)

Returns the value of attribute dirty_map.



42
43
44
# File 'lib/terrestrial/configurations/conventional_configuration.rb', line 42

def dirty_map
  @dirty_map
end

#identity_mapObject (readonly)

Returns the value of attribute identity_map.



42
43
44
# File 'lib/terrestrial/configurations/conventional_configuration.rb', line 42

def identity_map
  @identity_map
end

#inflectorObject (readonly)

Returns the value of attribute inflector.



42
43
44
# File 'lib/terrestrial/configurations/conventional_configuration.rb', line 42

def inflector
  @inflector
end

#mappingsObject (readonly)

Returns the value of attribute mappings.



42
43
44
# File 'lib/terrestrial/configurations/conventional_configuration.rb', line 42

def mappings
  @mappings
end

#overridesObject (readonly)

Returns the value of attribute overrides.



42
43
44
# File 'lib/terrestrial/configurations/conventional_configuration.rb', line 42

def overrides
  @overrides
end

Instance Method Details

#add_association(mapping_name, type, options) ⇒ Object



74
75
76
# File 'lib/terrestrial/configurations/conventional_configuration.rb', line 74

def add_association(mapping_name, type, options)
  @associations_by_mapping.fetch(mapping_name).push([type, options])
end

#add_override(mapping_name, attrs) ⇒ Object



59
60
61
62
63
# File 'lib/terrestrial/configurations/conventional_configuration.rb', line 59

def add_override(mapping_name, attrs)
  overrides = @overrides.fetch(mapping_name, {}).merge(attrs)

  @overrides.store(mapping_name, overrides)
end

#add_subset(mapping_name, subset_name, block) ⇒ Object



65
66
67
68
69
70
71
72
# File 'lib/terrestrial/configurations/conventional_configuration.rb', line 65

def add_subset(mapping_name, subset_name, block)
  @subset_queries.store(
    mapping_name,
    @subset_queries.fetch(mapping_name, {}).merge(
      subset_name => block,
    )
  )
end

#setup_mapping(mapping_name, &block) ⇒ Object



44
45
46
47
48
49
50
51
52
53
# File 'lib/terrestrial/configurations/conventional_configuration.rb', line 44

def setup_mapping(mapping_name, &block)
  @associations_by_mapping[mapping_name] ||= []
  @overrides[mapping_name] ||= {}

  block && block.call(
    MappingConfigOptionsProxy.new(self, mapping_name)
  )

  self
end