Module: InverseOf::Reflection::AssociationReflection
- Defined in:
- lib/inverse_of.rb
Class Method Summary collapse
Instance Method Summary collapse
- #check_validity_of_inverse! ⇒ Object
- #check_validity_with_inverse_of! ⇒ Object
- #has_inverse? ⇒ Boolean
- #inverse_of ⇒ Object
- #polymorphic_inverse_of(associated_class) ⇒ Object
Class Method Details
.included(base) ⇒ Object
15 16 17 |
# File 'lib/inverse_of.rb', line 15 def self.included(base) base.alias_method_chain :check_validity!, :inverse_of end |
Instance Method Details
#check_validity_of_inverse! ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/inverse_of.rb', line 24 def check_validity_of_inverse! unless [:polymorphic] if has_inverse? && inverse_of.nil? raise InverseOfAssociationNotFoundError.new(self) end end end |
#check_validity_with_inverse_of! ⇒ Object
19 20 21 22 |
# File 'lib/inverse_of.rb', line 19 def check_validity_with_inverse_of! check_validity_of_inverse! check_validity_without_inverse_of! end |
#has_inverse? ⇒ Boolean
32 33 34 |
# File 'lib/inverse_of.rb', line 32 def has_inverse? !@options[:inverse_of].nil? end |
#inverse_of ⇒ Object
36 37 38 39 40 |
# File 'lib/inverse_of.rb', line 36 def inverse_of if has_inverse? @inverse_of ||= klass.reflect_on_association([:inverse_of]) end end |
#polymorphic_inverse_of(associated_class) ⇒ Object
42 43 44 45 46 47 48 49 50 |
# File 'lib/inverse_of.rb', line 42 def polymorphic_inverse_of(associated_class) if has_inverse? if inverse_relationship = associated_class.reflect_on_association([:inverse_of]) inverse_relationship else raise InverseOfAssociationNotFoundError.new(self, associated_class) end end end |