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
- #belongs_to? ⇒ Boolean
- #counter_cache_hack? ⇒ Boolean
- #habtm? ⇒ Boolean
- #has_many? ⇒ Boolean
- #has_one? ⇒ Boolean
-
#initialize(association) ⇒ Abstract
constructor
A new instance of Abstract.
- #inverse_for?(klass) ⇒ Boolean
- #polymorphic? ⇒ Boolean
- #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_reflection ⇒ Object
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
67 68 69 70 71 72 |
# File 'lib/active_scaffold/data_structures/association/abstract.rb', line 67 def reverse(klass = nil) unless polymorphic? || defined?(@reverse) @reverse ||= inverse || get_reverse.try(:name) end @reverse || (get_reverse(klass).try(:name) unless klass.nil?) end |
Instance Method Details
#allow_join? ⇒ Boolean
9 10 11 |
# File 'lib/active_scaffold/data_structures/association/abstract.rb', line 9 def allow_join? !polymorphic? end |
#belongs_to? ⇒ Boolean
13 14 15 |
# File 'lib/active_scaffold/data_structures/association/abstract.rb', line 13 def belongs_to? @association.macro == :belongs_to end |
#counter_cache_hack? ⇒ Boolean
55 56 57 |
# File 'lib/active_scaffold/data_structures/association/abstract.rb', line 55 def counter_cache_hack? false end |
#habtm? ⇒ Boolean
25 26 27 |
# File 'lib/active_scaffold/data_structures/association/abstract.rb', line 25 def habtm? @association.macro == :has_and_belongs_to_many end |
#has_many? ⇒ Boolean
21 22 23 |
# File 'lib/active_scaffold/data_structures/association/abstract.rb', line 21 def has_many? @association.macro == :has_many end |
#has_one? ⇒ Boolean
17 18 19 |
# File 'lib/active_scaffold/data_structures/association/abstract.rb', line 17 def has_one? @association.macro == :has_one end |
#inverse_for?(klass) ⇒ Boolean
74 75 76 77 |
# File 'lib/active_scaffold/data_structures/association/abstract.rb', line 74 def inverse_for?(klass) inverse_class = reverse_association(klass).try(:inverse_klass) inverse_class.present? && (inverse_class == klass || klass < inverse_class) end |
#polymorphic? ⇒ Boolean
37 38 39 |
# File 'lib/active_scaffold/data_structures/association/abstract.rb', line 37 def polymorphic? false end |
#quoted_primary_key ⇒ Object
63 64 65 |
# File 'lib/active_scaffold/data_structures/association/abstract.rb', line 63 def quoted_primary_key raise "define quoted_primary_key method in #{self.class.name} class" end |
#quoted_table_name ⇒ Object
59 60 61 |
# File 'lib/active_scaffold/data_structures/association/abstract.rb', line 59 def quoted_table_name raise "define quoted_table_name method in #{self.class.name} class" end |
#readonly? ⇒ Boolean
41 42 43 |
# File 'lib/active_scaffold/data_structures/association/abstract.rb', line 41 def readonly? false end |
#respond_to_target? ⇒ Boolean
51 52 53 |
# File 'lib/active_scaffold/data_structures/association/abstract.rb', line 51 def respond_to_target? false end |
#reverse_association(klass = nil) ⇒ Object
79 80 81 82 83 84 85 86 87 |
# File 'lib/active_scaffold/data_structures/association/abstract.rb', line 79 def reverse_association(klass = nil) assoc = if polymorphic? get_reverse(klass) unless klass.nil? else return unless reverse_name = reverse(klass) reflect_on_association(reverse_name) end self.class.new(assoc) if assoc end |
#scope ⇒ Object
49 |
# File 'lib/active_scaffold/data_structures/association/abstract.rb', line 49 def scope; end |
#singular? ⇒ Boolean
29 30 31 |
# File 'lib/active_scaffold/data_structures/association/abstract.rb', line 29 def singular? !collection? end |
#source_reflection ⇒ Object
47 |
# File 'lib/active_scaffold/data_structures/association/abstract.rb', line 47 def source_reflection; end |
#through? ⇒ Boolean
33 34 35 |
# File 'lib/active_scaffold/data_structures/association/abstract.rb', line 33 def through? false end |
#through_reflection ⇒ Object
45 |
# File 'lib/active_scaffold/data_structures/association/abstract.rb', line 45 def through_reflection; end |