Class: Dbee::Dsl::Association

Inherits:
Object
  • Object
show all
Defined in:
lib/dbee/dsl/association.rb

Overview

The main logic that can take input from model association declaration and turn it into usable information.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(on_class_name, inflector, name, opts = {}) ⇒ Association

Returns a new instance of Association.

Raises:

  • (ArgumentError)


17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/dbee/dsl/association.rb', line 17

def initialize(on_class_name, inflector, name, opts = {})
  raise ArgumentError, 'on_class_name is required'  if on_class_name.to_s.empty?
  raise ArgumentError, 'inflector is required'      unless inflector
  raise ArgumentError, 'name is required'           if name.to_s.empty?

  @on_class_name     = on_class_name
  @inflector         = inflector
  @name              = name.to_s
  @opts              = opts || {}
  @constant_resolver = ConstantResolver.new

  freeze
end

Instance Attribute Details

#inflectorObject (readonly)

Returns the value of attribute inflector.



15
16
17
# File 'lib/dbee/dsl/association.rb', line 15

def inflector
  @inflector
end

#nameObject (readonly)

Returns the value of attribute name.



15
16
17
# File 'lib/dbee/dsl/association.rb', line 15

def name
  @name
end

#on_class_nameObject (readonly)

Returns the value of attribute on_class_name.



15
16
17
# File 'lib/dbee/dsl/association.rb', line 15

def on_class_name
  @on_class_name
end

#optsObject (readonly)

Returns the value of attribute opts.



15
16
17
# File 'lib/dbee/dsl/association.rb', line 15

def opts
  @opts
end

Instance Method Details

#constraintsObject



35
36
37
# File 'lib/dbee/dsl/association.rb', line 35

def constraints
  opts[:constraints] || []
end

#model_constantObject



31
32
33
# File 'lib/dbee/dsl/association.rb', line 31

def model_constant
  constant_resolver.constantize(class_name)
end