Class: Preflight::Rules::RootHasKeys

Inherits:
Object
  • Object
show all
Defined in:
lib/preflight/rules/root_has_keys.rb

Overview

ensure the root dict has the specified keys

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*keys) ⇒ RootHasKeys

Returns a new instance of RootHasKeys.



9
10
11
# File 'lib/preflight/rules/root_has_keys.rb', line 9

def initialize(*keys)
  @keys = keys.flatten
end

Class Method Details

.rule_typeObject



13
14
15
# File 'lib/preflight/rules/root_has_keys.rb', line 13

def self.rule_type
  :hash
end

Instance Method Details

#messages(ohash) ⇒ Object



17
18
19
20
21
22
23
# File 'lib/preflight/rules/root_has_keys.rb', line 17

def messages(ohash)
  root = ohash.object(ohash.trailer[:Root])
  missing = @keys - root.keys
  missing.map { |key|
    "Root dict missing required key #{key}"
  }
end