Class: Dbee::Dsl::Association
- Inherits:
-
Object
- Object
- Dbee::Dsl::Association
- 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
-
#inflector ⇒ Object
readonly
Returns the value of attribute inflector.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#on_class_name ⇒ Object
readonly
Returns the value of attribute on_class_name.
-
#opts ⇒ Object
readonly
Returns the value of attribute opts.
Instance Method Summary collapse
- #constraints ⇒ Object
-
#initialize(on_class_name, inflector, name, opts = {}) ⇒ Association
constructor
A new instance of Association.
- #model_constant ⇒ Object
Constructor Details
#initialize(on_class_name, inflector, name, opts = {}) ⇒ Association
Returns a new instance of Association.
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
#inflector ⇒ Object (readonly)
Returns the value of attribute inflector.
15 16 17 |
# File 'lib/dbee/dsl/association.rb', line 15 def inflector @inflector end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
15 16 17 |
# File 'lib/dbee/dsl/association.rb', line 15 def name @name end |
#on_class_name ⇒ Object (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 |
#opts ⇒ Object (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
#constraints ⇒ Object
35 36 37 |
# File 'lib/dbee/dsl/association.rb', line 35 def constraints opts[:constraints] || [] end |
#model_constant ⇒ Object
31 32 33 |
# File 'lib/dbee/dsl/association.rb', line 31 def model_constant constant_resolver.constantize(class_name) end |