Class: ConditionalMessages::Rule
- Inherits:
-
Object
- Object
- ConditionalMessages::Rule
- Defined in:
- lib/conditional_messages/rule.rb
Instance Attribute Summary collapse
-
#condition ⇒ Object
readonly
Returns the value of attribute condition.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #apply(context) ⇒ Object
- #default_points ⇒ Object
-
#initialize(options = {}, &condition) ⇒ Rule
constructor
A new instance of Rule.
- #points ⇒ Object
- #required? ⇒ Boolean
Constructor Details
#initialize(options = {}, &condition) ⇒ Rule
7 8 9 10 |
# File 'lib/conditional_messages/rule.rb', line 7 def initialize( = {}, &condition) = @condition = condition || raise(UndefinedRuleError) end |
Instance Attribute Details
#condition ⇒ Object (readonly)
Returns the value of attribute condition.
5 6 7 |
# File 'lib/conditional_messages/rule.rb', line 5 def condition @condition end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
5 6 7 |
# File 'lib/conditional_messages/rule.rb', line 5 def end |
Instance Method Details
#apply(context) ⇒ Object
24 25 26 |
# File 'lib/conditional_messages/rule.rb', line 24 def apply(context) context.instance_eval(&condition) end |
#default_points ⇒ Object
20 21 22 |
# File 'lib/conditional_messages/rule.rb', line 20 def default_points required? ? 100 : 10 end |
#points ⇒ Object
16 17 18 |
# File 'lib/conditional_messages/rule.rb', line 16 def points .fetch(:points) { default_points } end |
#required? ⇒ Boolean
12 13 14 |
# File 'lib/conditional_messages/rule.rb', line 12 def required? .fetch(:required) { false } end |