Class: Trailblazer::Finder::Find
- Inherits:
-
Object
- Object
- Trailblazer::Finder::Find
- Defined in:
- lib/trailblazer/finder/find.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#filters ⇒ Object
readonly
Returns the value of attribute filters.
-
#paging ⇒ Object
readonly
Returns the value of attribute paging.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#sorting ⇒ Object
readonly
Returns the value of attribute sorting.
Instance Method Summary collapse
-
#initialize(entity, params, filters, paging = nil, sorting = nil, config = nil) ⇒ Find
constructor
A new instance of Find.
- #process_filters(ctx) ⇒ Object
- #process_paging(ctx) ⇒ Object
- #process_sorting(ctx) ⇒ Object
- #query(ctx) ⇒ Object
Constructor Details
#initialize(entity, params, filters, paging = nil, sorting = nil, config = nil) ⇒ Find
Returns a new instance of Find.
8 9 10 11 12 13 14 15 |
# File 'lib/trailblazer/finder/find.rb', line 8 def initialize(entity, params, filters, paging = nil, sorting = nil, config = nil) @entity = entity @filters = filters @params = params @paging = paging || {} @sorting = sorting || {} @config = config || {} end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
6 7 8 |
# File 'lib/trailblazer/finder/find.rb', line 6 def config @config end |
#filters ⇒ Object (readonly)
Returns the value of attribute filters.
6 7 8 |
# File 'lib/trailblazer/finder/find.rb', line 6 def filters @filters end |
#paging ⇒ Object (readonly)
Returns the value of attribute paging.
6 7 8 |
# File 'lib/trailblazer/finder/find.rb', line 6 def paging @paging end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
6 7 8 |
# File 'lib/trailblazer/finder/find.rb', line 6 def params @params end |
#sorting ⇒ Object (readonly)
Returns the value of attribute sorting.
6 7 8 |
# File 'lib/trailblazer/finder/find.rb', line 6 def sorting @sorting end |
Instance Method Details
#process_filters(ctx) ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/trailblazer/finder/find.rb', line 17 def process_filters(ctx) @params.reduce(@entity) do |entity, (name, value)| filter = @filters[name.to_sym] || @filters[name] new_entity = ctx.instance_exec entity, filter[:name], value, &filter[:handler] new_entity || entity end end |
#process_paging(ctx) ⇒ Object
25 26 27 28 |
# File 'lib/trailblazer/finder/find.rb', line 25 def process_paging(ctx) ctx.instance_exec @paging[:current_page], @paging[:per_page], (@sorting.empty? ? (process_filters ctx) : (process_sorting ctx)), &@paging[:handler] end |
#process_sorting(ctx) ⇒ Object
30 31 32 |
# File 'lib/trailblazer/finder/find.rb', line 30 def process_sorting(ctx) ctx.instance_exec @sorting, (process_filters ctx), &@sorting[:handler] end |
#query(ctx) ⇒ Object
34 35 36 37 38 39 |
# File 'lib/trailblazer/finder/find.rb', line 34 def query(ctx) return process_paging ctx unless @paging.empty? || @paging.nil? return process_sorting ctx unless @sorting.empty? || @sorting.nil? process_filters ctx end |