Module: Dase::RelationInstanceMethods
- Defined in:
- lib/dase/mp_active_record.rb
Instance Method Summary collapse
- #dase_values ⇒ Object
- #extract_proc_argument(args, options) ⇒ Object
- #includes_count_of(*args) ⇒ Object
- #merge(other, *args) ⇒ Object
Instance Method Details
#dase_values ⇒ Object
3 4 5 |
# File 'lib/dase/mp_active_record.rb', line 3 def dase_values @dase_values ||= {} end |
#extract_proc_argument(args, options) ⇒ Object
21 22 23 24 25 26 |
# File 'lib/dase/mp_active_record.rb', line 21 def extract_proc_argument(args, ) if args.last.is_a?(Proc) raise "Can't use :proc option together with ->{} syntax" if .has_key?(:proc) [:proc] = args.pop end end |
#includes_count_of(*args) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/dase/mp_active_record.rb', line 7 def includes_count_of(*args) = args. extract_proc_argument(args, ) (args, ) apply_synonyms() return self if args.empty? clone.tap do |relation| args.each do |arg| counter_name = ([:as] || "#{arg}_count").to_sym relation.dase_values[counter_name] = .merge(as: counter_name, association: arg.to_sym) end end end |
#merge(other, *args) ⇒ Object
28 29 30 31 32 |
# File 'lib/dase/mp_active_record.rb', line 28 def merge(other, *args) super.tap do |result| result.dase_values.merge!(other.dase_values) if other # other == nil is fine too end end |