Class: Kms::EntryDrop::Scope
- Inherits:
-
Object
- Object
- Kms::EntryDrop::Scope
- Defined in:
- lib/drops/kms/entry_drop.rb
Overview
overriding methods cause we work with ‘json’ column
Instance Method Summary collapse
Instance Method Details
#find_all_by(_, fields = {}) ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/drops/kms/entry_drop.rb', line 17 def find_all_by(_, fields={}) fields, = Liquor::Drop.unwrap_scope_arguments([ fields ]) plain_fields, json_fields = fields_partition(fields) result = @source.where(fields_query(fields), *(json_fields.values + plain_fields.values).map(&:to_s)) Liquor::DropDelegation.wrap_scope(result) end |
#find_by(_, fields = {}) ⇒ Object
9 10 11 12 13 14 15 |
# File 'lib/drops/kms/entry_drop.rb', line 9 def find_by(_, fields={}) fields, = Liquor::Drop.unwrap_scope_arguments([ fields ]) plain_fields, json_fields = fields_partition(fields) result = @source.where(fields_query(fields), *(json_fields.values + plain_fields.values).map(&:to_s)).first Liquor::DropDelegation.wrap_element result if result end |
#order(*args) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/drops/kms/entry_drop.rb', line 25 def order(*args) args = Liquor::Drop.unwrap_scope_arguments(args) parsed_args = args.map do |arg| order_clause = arg.split(' ') if order_clause[0].in? Kms::Entry.column_names - ['values'] arg else ["values ->> '#{order_clause[0]}'", order_clause[1].to_s].join(' ') end end # we use reorder because by default we order by position Liquor::DropDelegation.wrap_scope @source.reorder(*parsed_args) end |