Class: Kanal::Core::Conditions::ConditionStorage
- Inherits:
-
Object
- Object
- Kanal::Core::Conditions::ConditionStorage
- Includes:
- Logging::Logger
- Defined in:
- lib/kanal/core/conditions/condition_storage.rb
Overview
This class contains all needed functionality to store, search conditions
Instance Method Summary collapse
- #condition_pack_exists?(pack) ⇒ Boolean
- #condition_pack_or_condition_exists?(name) ⇒ Boolean
- #get_condition_pack_by_name(name) ⇒ Object
- #get_condition_pack_by_name!(name) ⇒ Object
-
#initialize ⇒ ConditionStorage
constructor
A new instance of ConditionStorage.
- #register_condition_pack(pack) ⇒ Object
Methods included from Logging::Logger
Constructor Details
#initialize ⇒ ConditionStorage
Returns a new instance of ConditionStorage.
13 14 15 |
# File 'lib/kanal/core/conditions/condition_storage.rb', line 13 def initialize @condition_packs = [] end |
Instance Method Details
#condition_pack_exists?(pack) ⇒ Boolean
68 69 70 |
# File 'lib/kanal/core/conditions/condition_storage.rb', line 68 def condition_pack_exists?(pack) !(@condition_packs.find { |cp| cp.name == pack.name }).nil? end |
#condition_pack_or_condition_exists?(name) ⇒ Boolean
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/kanal/core/conditions/condition_storage.rb', line 33 def condition_pack_or_condition_exists?(name) pack = get_condition_pack_by_name name unless pack found_condition = false # Checking every pack for conditions inside of it @condition_packs.each do |cp| condition = cp.get_condition_by_name name if condition found_condition = true break end end return found_condition end !pack.nil? end |
#get_condition_pack_by_name(name) ⇒ Object
29 30 31 |
# File 'lib/kanal/core/conditions/condition_storage.rb', line 29 def get_condition_pack_by_name(name) @condition_packs.find { |p| p.name == name } end |
#get_condition_pack_by_name!(name) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/kanal/core/conditions/condition_storage.rb', line 17 def get_condition_pack_by_name!(name) pack = get_condition_pack_by_name name unless pack logger.fatal "Attempted to request unregistered condition pack #{name} from ConditionStorage" raise "Condition pack #{name} is not registered, but was requested from ConditionStorage" end pack end |
#register_condition_pack(pack) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/kanal/core/conditions/condition_storage.rb', line 54 def register_condition_pack(pack) return if condition_pack_exists? pack unless pack.is_a? ConditionPack logger.fatal "Attempted to register condition pack which isn't of ConditionPack class" raise "Condition pack should be descendant of ConditionPack class" end logger.debug "Registering condition pack '#{pack.name}'" @condition_packs.append pack end |