Class: Associationist::Config
- Inherits:
-
Object
- Object
- Associationist::Config
- Defined in:
- lib/associationist/config.rb
Instance Method Summary collapse
- #check ⇒ Object
- #class_name ⇒ Object
-
#initialize(config) ⇒ Config
constructor
A new instance of Config.
- #loader_proc ⇒ Object
- #name ⇒ Object
- #preloader_proc ⇒ Object
- #scope_proc ⇒ Object
- #type ⇒ Object
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
#check ⇒ Object
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_name ⇒ Object
33 34 35 |
# File 'lib/associationist/config.rb', line 33 def class_name @config[:class_name] end |
#loader_proc ⇒ Object
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 |
#name ⇒ Object
7 8 9 |
# File 'lib/associationist/config.rb', line 7 def name @config[:name] end |
#preloader_proc ⇒ Object
21 22 23 |
# File 'lib/associationist/config.rb', line 21 def preloader_proc @config[:preloader] end |
#scope_proc ⇒ Object
29 30 31 |
# File 'lib/associationist/config.rb', line 29 def scope_proc @config[:scope] end |
#type ⇒ Object
25 26 27 |
# File 'lib/associationist/config.rb', line 25 def type @config[:type] || :singular end |