Class: AdjustableSchema::ActiveRecord::Association
- Inherits:
-
Struct
- Object
- Struct
- AdjustableSchema::ActiveRecord::Association
- Defined in:
- lib/adjustable_schema/active_record/association.rb,
lib/adjustable_schema/active_record/association/naming.rb
Defined Under Namespace
Modules: Scopes
Instance Attribute Summary collapse
-
#direction ⇒ Object
Returns the value of attribute direction.
-
#owner ⇒ Object
Returns the value of attribute owner.
-
#role ⇒ Object
Returns the value of attribute role.
-
#target ⇒ Object
Returns the value of attribute target.
Instance Method Summary collapse
- #child? ⇒ Boolean
- #define ⇒ Object
- #hierarchy? ⇒ Boolean
- #parent? ⇒ Boolean
- #recursive? ⇒ Boolean
- #roleless? ⇒ Boolean
- #source? ⇒ Boolean
- #target? ⇒ Boolean
Instance Attribute Details
#direction ⇒ Object
Returns the value of attribute direction
3 4 5 |
# File 'lib/adjustable_schema/active_record/association.rb', line 3 def direction @direction end |
#owner ⇒ Object
Returns the value of attribute owner
3 4 5 |
# File 'lib/adjustable_schema/active_record/association.rb', line 3 def owner @owner end |
#role ⇒ Object
Returns the value of attribute role
3 4 5 |
# File 'lib/adjustable_schema/active_record/association.rb', line 3 def role @role end |
#target ⇒ Object
Returns the value of attribute target
3 4 5 |
# File 'lib/adjustable_schema/active_record/association.rb', line 3 def target @target end |
Instance Method Details
#child? ⇒ Boolean
39 |
# File 'lib/adjustable_schema/active_record/association.rb', line 39 def child? = (recursive? and source?) |
#define ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/adjustable_schema/active_record/association.rb', line 7 def define name.tap do |association_name| association = self # save context has_many association_name, **( = { through: define_relationships, source: direction, source_type: target.base_class.name, class_name: target.name }) do include Scopes include Scopes::Recursive if association.recursive? end define_scopes define_methods unless role # HACK: using `try` to overcome a Rails bug # (see https://github.com/rails/rails/issues/40109) has_many roleless_name, -> { try :roleless }, ** if child? define_role_methods end end end |
#hierarchy? ⇒ Boolean
41 |
# File 'lib/adjustable_schema/active_record/association.rb', line 41 def hierarchy? = (child? and roleless?) |
#parent? ⇒ Boolean
40 |
# File 'lib/adjustable_schema/active_record/association.rb', line 40 def parent? = (recursive? and target?) |
#recursive? ⇒ Boolean
35 |
# File 'lib/adjustable_schema/active_record/association.rb', line 35 def recursive? = target == owner |
#roleless? ⇒ Boolean
36 |
# File 'lib/adjustable_schema/active_record/association.rb', line 36 def roleless? = !role |
#source? ⇒ Boolean
37 |
# File 'lib/adjustable_schema/active_record/association.rb', line 37 def source? = direction == :source |
#target? ⇒ Boolean
38 |
# File 'lib/adjustable_schema/active_record/association.rb', line 38 def target? = direction == :target |