Class: BBAttributeFilters::Conditions::Condition
- Inherits:
-
Object
- Object
- BBAttributeFilters::Conditions::Condition
- Defined in:
- lib/bbattribute_filters/conditions/condition.rb
Overview
The base class for all AttributeConditions. E.g. allows the :if :unless conditions to be used when creating attributes
Constant Summary collapse
- ALLOWED_CONDITIONS =
%i[if unless none].freeze
Instance Attribute Summary collapse
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #evaluate(evaluator) ⇒ Object
- #exclude?(_serializer) ⇒ Boolean
- #include?(_serializer) ⇒ Boolean
-
#initialize(type, on) ⇒ Condition
constructor
A new instance of Condition.
Constructor Details
#initialize(type, on) ⇒ Condition
Returns a new instance of Condition.
16 17 18 19 20 21 22 23 24 |
# File 'lib/bbattribute_filters/conditions/condition.rb', line 16 def initialize(type, on) unless invalid_type?(type) raise ArgumentError, 'BBAttributeFilters::Conditions::Condition - Type should be :if, :unless or :none' end @type = type @on = on @handler = build_condition_handler(on) end |
Instance Attribute Details
#type ⇒ Object (readonly)
Returns the value of attribute type.
14 15 16 |
# File 'lib/bbattribute_filters/conditions/condition.rb', line 14 def type @type end |
Instance Method Details
#evaluate(evaluator) ⇒ Object
26 27 28 |
# File 'lib/bbattribute_filters/conditions/condition.rb', line 26 def evaluate(evaluator) @handler.evaluate(evaluator) end |
#exclude?(_serializer) ⇒ Boolean
34 35 36 |
# File 'lib/bbattribute_filters/conditions/condition.rb', line 34 def exclude?(_serializer) false end |
#include?(_serializer) ⇒ Boolean
30 31 32 |
# File 'lib/bbattribute_filters/conditions/condition.rb', line 30 def include?(_serializer) true end |