Class: Filch::RansackPlus
- Inherits:
-
Object
- Object
- Filch::RansackPlus
- Defined in:
- lib/filch/ransack_plus.rb
Overview
Ransack for results, and then manipulate data as necessary.
Instance Attribute Summary collapse
-
#q ⇒ Object
readonly
Returns the value of attribute q.
-
#result ⇒ Object
readonly
Returns the value of attribute result.
Instance Method Summary collapse
-
#initialize(model, params) ⇒ RansackPlus
constructor
A new instance of RansackPlus.
-
#limit_fix(limit = 50) ⇒ Object
adjust the limit for certain scenarios.
-
#ransack_result ⇒ Object
get the results!.
Constructor Details
#initialize(model, params) ⇒ RansackPlus
Returns a new instance of RansackPlus.
4 5 6 7 8 9 |
# File 'lib/filch/ransack_plus.rb', line 4 def initialize(model, params) @params = params @params[:limit] = limit_fix(params[:limit]) if @params @q = model.ransack(@params) @result = ransack_result end |
Instance Attribute Details
#q ⇒ Object (readonly)
Returns the value of attribute q.
10 11 12 |
# File 'lib/filch/ransack_plus.rb', line 10 def q @q end |
#result ⇒ Object (readonly)
Returns the value of attribute result.
10 11 12 |
# File 'lib/filch/ransack_plus.rb', line 10 def result @result end |
Instance Method Details
#limit_fix(limit = 50) ⇒ Object
adjust the limit for certain scenarios. ransack doesn’t return a list if limit is 1 so change to 2. also, default to 50 if limit is not set.
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/filch/ransack_plus.rb', line 21 def limit_fix(limit = 50) case limit when '0' @params.delete(:limit) when '1' '2' when '' '50' else limit end end |
#ransack_result ⇒ Object
get the results!
13 14 15 16 |
# File 'lib/filch/ransack_plus.rb', line 13 def ransack_result return [] unless @params @q.result end |