class Togls::Rule

Rule

The Rule is an abstract base class that is intended to act as an interface for other rules to be implemented against.

Attributes

data[R]
id[R]
type_id[R]

Public Class Methods

description() click to toggle source
# File lib/togls/rule.rb, line 13
def self.description
  raise Togls::NotImplemented, "Rule type description not implemented"
end
new(id, type_id, data = nil, target_type: Togls::TargetTypes::NOT_SET) click to toggle source
# 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
target_type() click to toggle source
# File lib/togls/rule.rb, line 17
def self.target_type
  Togls::TargetTypes::NOT_SET
end
title() click to toggle source
# File lib/togls/rule.rb, line 9
def self.title
  raise Togls::NotImplemented, "Rule type title not implemented"
end

Public Instance Methods

missing_target_type?() click to toggle source
# 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) click to toggle source
# 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() click to toggle source
# 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