Module: RailsDynamicAssociations::ActiveRecord::Relations::ClassAndInstanceMethods
- Defined in:
- lib/rails_dynamic_associations/active_record/relations.rb
Instance Method Summary collapse
-
#find_relations(args = {}) ⇒ Object
TODO: use keyword arguments.
- #relative?(args = {}) ⇒ Boolean
- #relatives(args = {}) ⇒ Object
Instance Method Details
#find_relations(args = {}) ⇒ Object
TODO: use keyword arguments
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/rails_dynamic_associations/active_record/relations.rb', line 22 def find_relations args = {} directions = RailsDynamicAssociations.directions for association, method in directions do args[association] = args.delete method end as = [ args[:as] ].flatten if directions.keys.inject(nil) { |r, k| !r ^ !args[k] } then # direction specified for association, method in directions do next unless args[association] return (as.present? ? source_relations.named(as) : source_relations ).send method, args[association] end else # both directions directions.map do |association, method| as.present? ? send("#{association}_relations").named(as) : send("#{association}_relations") end.sum end end |
#relative?(args = {}) ⇒ Boolean
49 50 51 52 |
# File 'lib/rails_dynamic_associations/active_record/relations.rb', line 49 def relative? args = {} find_relations(args). present? end |
#relatives(args = {}) ⇒ Object
54 55 56 57 58 59 |
# File 'lib/rails_dynamic_associations/active_record/relations.rb', line 54 def relatives args = {} find_relations(args). map { |r| ([ r.source, r.target ] - [ self ]).first }.uniq end |