Class: Associationist::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/associationist/config.rb

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Config

Returns a new instance of Config.



3
4
5
# File 'lib/associationist/config.rb', line 3

def initialize config
  @config = config
end

Instance Method Details

#checkObject



37
38
39
40
41
42
43
44
45
# File 'lib/associationist/config.rb', line 37

def check
  if @config[:loader] && @config[:scope]
    raise "cannot define both loader and scope"
  end

  if @config[:type] && !@config[:scope]
    raise "type option only effects when scope defined"
  end
end

#class_nameObject



33
34
35
# File 'lib/associationist/config.rb', line 33

def class_name
  @config[:class_name]
end

#loader_procObject



11
12
13
14
15
16
17
18
19
# File 'lib/associationist/config.rb', line 11

def loader_proc
  if @config[:loader]
    @config[:loader]
  elsif preloader_proc
    -> record {
      (preloader_proc.call [record])[record]
    }
  end
end

#nameObject



7
8
9
# File 'lib/associationist/config.rb', line 7

def name
  @config[:name]
end

#preloader_procObject



21
22
23
# File 'lib/associationist/config.rb', line 21

def preloader_proc
  @config[:preloader]
end

#scope_procObject



29
30
31
# File 'lib/associationist/config.rb', line 29

def scope_proc
  @config[:scope]
end

#typeObject



25
26
27
# File 'lib/associationist/config.rb', line 25

def type
  @config[:type] || :singular
end