Class: Togls::Rule

Inherits:
Object
  • Object
show all
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

Togls::Rules::Boolean, Togls::Rules::Group

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#dataObject (readonly)

Returns the value of attribute data.



7
8
9
# File 'lib/togls/rule.rb', line 7

def data
  @data
end

#idObject (readonly)

Returns the value of attribute id.



7
8
9
# File 'lib/togls/rule.rb', line 7

def id
  @id
end

#type_idObject (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

.descriptionObject



13
14
15
# File 'lib/togls/rule.rb', line 13

def self.description
  raise Togls::NotImplemented, "Rule type description not implemented"
end

.target_typeObject



17
18
19
# File 'lib/togls/rule.rb', line 17

def self.target_type
  Togls::TargetTypes::NOT_SET
end

.titleObject



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

Returns:

  • (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_typeObject



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