Class: Togls::Rule
- Inherits:
-
Object
- Object
- Togls::Rule
- Defined in:
- lib/togls/rule.rb
Overview
Rule
The Rule is an abstract base class that is intended to act as an interface for other rules to be implemented against.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#type_id ⇒ Object
readonly
Returns the value of attribute type_id.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(id, type_id, data = nil, target_type: Togls::TargetTypes::NOT_SET) ⇒ Rule
constructor
A new instance of Rule.
- #missing_target_type? ⇒ Boolean
- #run(key, target = nil) ⇒ Object
- #target_type ⇒ Object
Constructor Details
#initialize(id, type_id, data = nil, target_type: Togls::TargetTypes::NOT_SET) ⇒ Rule
Returns a new instance of Rule.
21 22 23 24 25 26 27 |
# File 'lib/togls/rule.rb', line 21 def initialize(id, type_id, data = nil, target_type: Togls::TargetTypes::NOT_SET) @id = id @type_id = type_id @data = data @target_type = target_type raise Togls::RuleMissingTargetType, "Rule '#{self.id}' of type '#{self.class}' is missing a required target type" if self.missing_target_type? end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
7 8 9 |
# File 'lib/togls/rule.rb', line 7 def data @data end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
7 8 9 |
# File 'lib/togls/rule.rb', line 7 def id @id end |
#type_id ⇒ Object (readonly)
Returns the value of attribute type_id.
7 8 9 |
# File 'lib/togls/rule.rb', line 7 def type_id @type_id end |
Class Method Details
.description ⇒ Object
13 14 15 |
# File 'lib/togls/rule.rb', line 13 def self.description raise Togls::NotImplemented, "Rule type description not implemented" end |
.target_type ⇒ Object
17 18 19 |
# File 'lib/togls/rule.rb', line 17 def self.target_type Togls::TargetTypes::NOT_SET end |
.title ⇒ Object
9 10 11 |
# File 'lib/togls/rule.rb', line 9 def self.title raise Togls::NotImplemented, "Rule type title not implemented" end |
Instance Method Details
#missing_target_type? ⇒ Boolean
39 40 41 42 |
# File 'lib/togls/rule.rb', line 39 def missing_target_type? return false if target_type && (target_type != Togls::TargetTypes::NOT_SET) return true end |
#run(key, target = nil) ⇒ Object
29 30 31 |
# File 'lib/togls/rule.rb', line 29 def run(key, target = nil) raise Togls::NotImplemented, "Rule's #run method must be implemented" end |
#target_type ⇒ Object
33 34 35 36 37 |
# File 'lib/togls/rule.rb', line 33 def target_type return @target_type if @target_type && @target_type != Togls::TargetTypes::NOT_SET return self.class.target_type unless self.class.target_type.nil? return Togls::TargetTypes::NOT_SET end |