Module: SomehowHasRelation::InstanceMethods
- Defined in:
- lib/somehow_has_relation.rb
Instance Method Summary collapse
- #somehow_found_or_recur(relation, condition = nil, opts = nil) ⇒ Object
- #somehow_recur(relation, through, filter) ⇒ Object
Instance Method Details
#somehow_found_or_recur(relation, condition = nil, opts = nil) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/somehow_has_relation.rb', line 49 def somehow_found_or_recur(relation, condition=nil, opts=nil) if self.class.send(:class_variable_defined?, :@@somehow_has_relation_options) opts ||= self.class.send(:class_variable_get, :@@somehow_has_relation_options) opts = [opts] unless opts.is_a? Array found = [] opts.each do |opt| begin if opt.has_key?(:through) found << somehow_recur(relation, opt[:through], opt[:if]) else return send_and_filter(relation, condition) end rescue found << [] end end found else send_and_filter(relation, condition) end end |
#somehow_recur(relation, through, filter) ⇒ Object
39 40 41 42 43 44 45 46 47 |
# File 'lib/somehow_has_relation.rb', line 39 def somehow_recur(relation, through, filter) first_step = send_and_filter(through) if first_step.is_a? Array first_step.map{|instance| instance.somehow_found_or_recur(relation, filter)} else first_step.somehow_found_or_recur(relation, filter) end end |