Module: Parascope::Query::ApiMethods
- Included in:
- Parascope::Query
- Defined in:
- lib/parascope/query/api_methods.rb
Instance Method Summary collapse
- #base_scope(&block) ⇒ Object (also: #base_dataset)
- #defaults(params = nil) ⇒ Object
- #guard(&block) ⇒ Object
- #guard_blocks ⇒ Object
- #query_blocks ⇒ Object
- #query_by(*presence_fields, **value_fields, &block) ⇒ Object (also: #query)
- #query_by!(*presence_fields, &block) ⇒ Object (also: #query!)
- #sift_blocks ⇒ Object
- #sift_by(*presence_fields, **value_fields, &block) ⇒ Object (also: #sifter)
- #sift_by!(*presence_fields, &block) ⇒ Object (also: #sifter!)
- #sorted_query_blocks ⇒ Object
Instance Method Details
#base_scope(&block) ⇒ Object Also known as: base_dataset
3 4 5 6 7 |
# File 'lib/parascope/query/api_methods.rb', line 3 def base_scope(&block) return @base_scope unless block_given? @base_scope = block end |
#defaults(params = nil) ⇒ Object
10 11 12 13 14 15 16 |
# File 'lib/parascope/query/api_methods.rb', line 10 def defaults(params = nil) @defaults ||= {} return @defaults if params.nil? @defaults = @defaults.merge(params) end |
#guard(&block) ⇒ Object
58 59 60 |
# File 'lib/parascope/query/api_methods.rb', line 58 def guard(&block) guard_blocks.push block end |
#guard_blocks ⇒ Object
70 71 72 |
# File 'lib/parascope/query/api_methods.rb', line 70 def guard_blocks @guard_blocks ||= [] end |
#query_blocks ⇒ Object
66 67 68 |
# File 'lib/parascope/query/api_methods.rb', line 66 def query_blocks @query_blocks ||= [] end |
#query_by(*presence_fields, **value_fields, &block) ⇒ Object Also known as: query
26 27 28 29 30 31 32 |
# File 'lib/parascope/query/api_methods.rb', line 26 def query_by(*presence_fields, **value_fields, &block) query_blocks.push Query::ApiBlock.new( presence_fields: presence_fields, value_fields: value_fields, block: block ) end |
#query_by!(*presence_fields, &block) ⇒ Object Also known as: query!
46 47 48 49 50 51 52 53 |
# File 'lib/parascope/query/api_methods.rb', line 46 def query_by!(*presence_fields, &block) query_blocks.push Query::ApiBlock.new( presence_fields: presence_fields, value_fields: {}, block: block, force: true ) end |
#sift_blocks ⇒ Object
62 63 64 |
# File 'lib/parascope/query/api_methods.rb', line 62 def sift_blocks @sift_blocks ||= [] end |
#sift_by(*presence_fields, **value_fields, &block) ⇒ Object Also known as: sifter
18 19 20 21 22 23 24 |
# File 'lib/parascope/query/api_methods.rb', line 18 def sift_by(*presence_fields, **value_fields, &block) sift_blocks.push Query::ApiBlock.new( presence_fields: presence_fields, value_fields: value_fields, block: block ) end |
#sift_by!(*presence_fields, &block) ⇒ Object Also known as: sifter!
37 38 39 40 41 42 43 44 |
# File 'lib/parascope/query/api_methods.rb', line 37 def sift_by!(*presence_fields, &block) sift_blocks.push Query::ApiBlock.new( presence_fields: presence_fields, value_fields: {}, block: block, force: true ) end |
#sorted_query_blocks ⇒ Object
74 75 76 77 78 79 80 |
# File 'lib/parascope/query/api_methods.rb', line 74 def sorted_query_blocks query_blocks.sort do |a, b| a.index == b.index \ ? query_blocks.index(a) <=> query_blocks.index(b) : a.index <=> b.index end end |