Class: SequelMapper::Configurations::ConventionalConfiguration

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

Defined Under Namespace

Classes: RelationConfigOptionsProxy

Instance Method Summary collapse

Constructor Details

#initialize(datastore) ⇒ ConventionalConfiguration

Returns a new instance of ConventionalConfiguration.



19
20
21
22
23
24
# File 'lib/sequel_mapper/configurations/conventional_configuration.rb', line 19

def initialize(datastore)
  @datastore = datastore
  @overrides = {}
  @subset_queries = {}
  @associations_by_mapping = {}
end

Instance Method Details

#[](mapping_name) ⇒ Object



29
30
31
# File 'lib/sequel_mapper/configurations/conventional_configuration.rb', line 29

def [](mapping_name)
  mappings[mapping_name]
end

#setup_mapping(mapping_name, &block) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/sequel_mapper/configurations/conventional_configuration.rb', line 33

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

  block.call(
    RelationConfigOptionsProxy.new(
      method(:add_override).to_proc.curry.call(mapping_name),
      method(:add_subset).to_proc.curry.call(mapping_name),
      @associations_by_mapping.fetch(mapping_name),
    )
  ) if block

  # TODO: more madness in this silly config this, kill it with fire.
  explicit_settings = @overrides[mapping_name] ||= {}
  explicit_settings[:factory] ||= raise_if_not_found_factory(mapping_name)

  self
end