Class: QueryFilter::Utils::UserConditions
- Inherits:
-
Object
- Object
- QueryFilter::Utils::UserConditions
- Defined in:
- lib/query_filter/utils/user_conditions.rb
Instance Attribute Summary collapse
-
#target ⇒ Object
readonly
Returns the value of attribute target.
Instance Method Summary collapse
- #conditions_lambdas ⇒ Object
- #empty? ⇒ Boolean
-
#initialize(target, options = {}) ⇒ UserConditions
constructor
A new instance of UserConditions.
- #passed? ⇒ Boolean
- #present? ⇒ Boolean
Constructor Details
#initialize(target, options = {}) ⇒ UserConditions
Returns a new instance of UserConditions.
8 9 10 11 12 13 14 |
# File 'lib/query_filter/utils/user_conditions.rb', line 8 def initialize(target, = {}) @target = target @options = @if = Array([:if]) @unless = Array([:unless]) end |
Instance Attribute Details
#target ⇒ Object (readonly)
Returns the value of attribute target.
6 7 8 |
# File 'lib/query_filter/utils/user_conditions.rb', line 6 def target @target end |
Instance Method Details
#conditions_lambdas ⇒ Object
31 32 33 34 |
# File 'lib/query_filter/utils/user_conditions.rb', line 31 def conditions_lambdas @if.map { |c| make_lambda c } + @unless.map { |c| invert_lambda make_lambda c } end |
#empty? ⇒ Boolean
23 24 25 |
# File 'lib/query_filter/utils/user_conditions.rb', line 23 def empty? @if.empty? && @unless.empty? end |
#passed? ⇒ Boolean
16 17 18 19 20 21 |
# File 'lib/query_filter/utils/user_conditions.rb', line 16 def passed? return true if empty? value = target.params conditions_lambdas.all? { |c| c.call(target, value) } end |
#present? ⇒ Boolean
27 28 29 |
# File 'lib/query_filter/utils/user_conditions.rb', line 27 def present? !empty? end |