Class: YamlBot::RulesBot

Inherits:
Object
  • Object
show all
Defined in:
lib/yaml_bot/rules_bot.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(rules = nil) ⇒ RulesBot

Returns a new instance of RulesBot.



8
9
10
# File 'lib/yaml_bot/rules_bot.rb', line 8

def initialize(rules = nil)
  @rules = rules
end

Instance Attribute Details

#rulesObject

Returns the value of attribute rules.



6
7
8
# File 'lib/yaml_bot/rules_bot.rb', line 6

def rules
  @rules
end

Instance Method Details

#validate_rulesObject

Raises:



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/yaml_bot/rules_bot.rb', line 12

def validate_rules
  raise ValidationError, '.yamlbot rules file is not set.' if @rules.nil?
  raise ValidationError, 'rules section not defined in .yamlbot file' if @rules['rules'].nil?
  validate_rules_keys(@rules['defaults']) unless @rules['defaults'].nil?
  if @rules['rules'].instance_of?(Array)
    validate_each_key_rule
  else
    msg = "The rules section of a rules file must define a list of keys.\n"
    raise ValidationError, msg
  end
end