Class: ActiveScaffold::DataStructures::Association::Abstract
- Defined in:
- lib/active_scaffold/data_structures/association/abstract.rb
Direct Known Subclasses
Instance Attribute Summary collapse
Instance Method Summary collapse
- #allow_join? ⇒ Boolean
- #as ⇒ Object
- #belongs_to? ⇒ Boolean
- #cache_count? ⇒ Boolean
- #collection? ⇒ Boolean
- #counter_cache ⇒ Object
- #counter_cache_hack? ⇒ Boolean
- #habtm? ⇒ Boolean
-
#has_many? ⇒ Boolean
rubocop:disable Naming/PredicateName.
-
#has_one? ⇒ Boolean
rubocop:disable Naming/PredicateName.
-
#initialize(association) ⇒ Abstract
constructor
A new instance of Abstract.
- #inverse_for?(klass) ⇒ Boolean
- #klass(record = nil) ⇒ Object
- #nested? ⇒ Boolean
- #polymorphic? ⇒ Boolean
- #primary_key ⇒ Object
- #quoted_primary_key ⇒ Object
- #quoted_table_name ⇒ Object
- #readonly? ⇒ Boolean
- #respond_to_target? ⇒ Boolean
- #reverse_association(klass = nil) ⇒ Object
- #scope ⇒ Object
- #singular? ⇒ Boolean
- #source_reflection ⇒ Object
- #through? ⇒ Boolean
- #through_collection? ⇒ Boolean
- #through_reflection ⇒ Object
- #through_singular? ⇒ Boolean
Constructor Details
#initialize(association) ⇒ Abstract
Returns a new instance of Abstract.
3 4 5 |
# File 'lib/active_scaffold/data_structures/association/abstract.rb', line 3 def initialize(association) @association = association end |
Instance Attribute Details
#reverse(klass = nil) ⇒ Object
103 104 105 106 |
# File 'lib/active_scaffold/data_structures/association/abstract.rb', line 103 def reverse(klass = nil) @reverse ||= inverse || get_reverse&.name unless polymorphic? @reverse || get_reverse(klass)&.name end |
Instance Method Details
#allow_join? ⇒ Boolean
11 12 13 |
# File 'lib/active_scaffold/data_structures/association/abstract.rb', line 11 def allow_join? !polymorphic? end |
#as ⇒ Object
85 |
# File 'lib/active_scaffold/data_structures/association/abstract.rb', line 85 def as; end |
#belongs_to? ⇒ Boolean
23 24 25 |
# File 'lib/active_scaffold/data_structures/association/abstract.rb', line 23 def belongs_to? @association.macro == :belongs_to end |
#cache_count? ⇒ Boolean
124 125 126 |
# File 'lib/active_scaffold/data_structures/association/abstract.rb', line 124 def cache_count? collection? && !ActiveScaffold::OrmChecks.tableless?(klass) && !reverse_association&.counter_cache end |
#collection? ⇒ Boolean
43 44 45 |
# File 'lib/active_scaffold/data_structures/association/abstract.rb', line 43 def collection? has_many? || habtm? end |
#counter_cache ⇒ Object
67 68 69 |
# File 'lib/active_scaffold/data_structures/association/abstract.rb', line 67 def counter_cache @association.[:counter_cache] end |
#counter_cache_hack? ⇒ Boolean
91 92 93 |
# File 'lib/active_scaffold/data_structures/association/abstract.rb', line 91 def counter_cache_hack? false end |
#habtm? ⇒ Boolean
35 36 37 |
# File 'lib/active_scaffold/data_structures/association/abstract.rb', line 35 def habtm? @association.macro == :has_and_belongs_to_many end |
#has_many? ⇒ Boolean
rubocop:disable Naming/PredicateName
31 32 33 |
# File 'lib/active_scaffold/data_structures/association/abstract.rb', line 31 def has_many? # rubocop:disable Naming/PredicateName @association.macro == :has_many end |
#has_one? ⇒ Boolean
rubocop:disable Naming/PredicateName
27 28 29 |
# File 'lib/active_scaffold/data_structures/association/abstract.rb', line 27 def has_one? # rubocop:disable Naming/PredicateName @association.macro == :has_one end |
#inverse_for?(klass) ⇒ Boolean
108 109 110 111 |
# File 'lib/active_scaffold/data_structures/association/abstract.rb', line 108 def inverse_for?(klass) inverse_class = reverse_association(klass)&.inverse_klass inverse_class.present? && (inverse_class == klass || klass < inverse_class) end |
#klass(record = nil) ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/active_scaffold/data_structures/association/abstract.rb', line 15 def klass(record = nil) if polymorphic? record&.send(foreign_type)&.safe_constantize else @association.klass end end |
#nested? ⇒ Boolean
51 52 53 |
# File 'lib/active_scaffold/data_structures/association/abstract.rb', line 51 def nested? false end |
#polymorphic? ⇒ Boolean
71 72 73 |
# File 'lib/active_scaffold/data_structures/association/abstract.rb', line 71 def polymorphic? false end |
#primary_key ⇒ Object
63 64 65 |
# File 'lib/active_scaffold/data_structures/association/abstract.rb', line 63 def primary_key @association.[:primary_key] end |
#quoted_primary_key ⇒ Object
99 100 101 |
# File 'lib/active_scaffold/data_structures/association/abstract.rb', line 99 def quoted_primary_key raise "define quoted_primary_key method in #{self.class.name} class" end |
#quoted_table_name ⇒ Object
95 96 97 |
# File 'lib/active_scaffold/data_structures/association/abstract.rb', line 95 def quoted_table_name raise "define quoted_table_name method in #{self.class.name} class" end |
#readonly? ⇒ Boolean
75 76 77 |
# File 'lib/active_scaffold/data_structures/association/abstract.rb', line 75 def readonly? false end |
#respond_to_target? ⇒ Boolean
87 88 89 |
# File 'lib/active_scaffold/data_structures/association/abstract.rb', line 87 def respond_to_target? false end |
#reverse_association(klass = nil) ⇒ Object
113 114 115 116 117 118 119 120 121 122 |
# File 'lib/active_scaffold/data_structures/association/abstract.rb', line 113 def reverse_association(klass = nil) assoc = if polymorphic? get_reverse(klass) unless klass.nil? else reverse_name = reverse(klass) reflect_on_association(reverse_name) if reverse_name end self.class.new(assoc) if assoc end |
#scope ⇒ Object
83 |
# File 'lib/active_scaffold/data_structures/association/abstract.rb', line 83 def scope; end |
#singular? ⇒ Boolean
39 40 41 |
# File 'lib/active_scaffold/data_structures/association/abstract.rb', line 39 def singular? !collection? end |
#source_reflection ⇒ Object
81 |
# File 'lib/active_scaffold/data_structures/association/abstract.rb', line 81 def source_reflection; end |
#through? ⇒ Boolean
47 48 49 |
# File 'lib/active_scaffold/data_structures/association/abstract.rb', line 47 def through? false end |
#through_collection? ⇒ Boolean
59 60 61 |
# File 'lib/active_scaffold/data_structures/association/abstract.rb', line 59 def through_collection? through? && through_reflection.collection? end |
#through_reflection ⇒ Object
79 |
# File 'lib/active_scaffold/data_structures/association/abstract.rb', line 79 def through_reflection; end |
#through_singular? ⇒ Boolean
55 56 57 |
# File 'lib/active_scaffold/data_structures/association/abstract.rb', line 55 def through_singular? through? && !through_reflection.collection? end |