Class: RhetButler::YamlType

Inherits:
Object
  • Object
show all
Defined in:
lib/rhet-butler/yaml-type.rb

Direct Known Subclasses

Includer, Slide, SlideContents, SlideGroup, SlideRenderer

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeYamlType

Returns a new instance of YamlType.



32
33
34
# File 'lib/rhet-butler/yaml-type.rb', line 32

def initialize
  setup_defaults
end

Class Method Details

.register(name) ⇒ Object



5
6
7
# File 'lib/rhet-butler/yaml-type.rb', line 5

def self.register(name)
  YAML.add_tag("!#{name}", self)
end

Instance Method Details

#check_config_hash(config_hash) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/rhet-butler/yaml-type.rb', line 12

def check_config_hash(config_hash)
  expected_keys = self.class.required_config + self.class.optional_config
  weird_keys = config_hash.keys.find_all{|key| !expected_keys.include?(key)}
  missing_keys = self.class.required_config.find_all{|key|
    !config_hash.has_key?(key)
  }
  unless weird_keys.empty?
    warn "Found weird keys: #{weird_keys.inspect} in #{config_hash.inspect}"
  end
  unless missing_keys.empty?
    raise "Missing required keys: #{missing_keys.inspect} in #{config_hash.inspect}"
  end
end

#init_with(coder) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/rhet-butler/yaml-type.rb', line 36

def init_with(coder)
  setup_defaults

  @config_hash = normalize_config(coder)

  check_config_hash(@config_hash)

  configure
rescue => ex
  puts "Processing #{coder.inspect}"
  raise
end

#setup_defaultsObject



9
10
# File 'lib/rhet-butler/yaml-type.rb', line 9

def setup_defaults
end

#value_from_config(name) ⇒ Object



26
27
28
29
30
# File 'lib/rhet-butler/yaml-type.rb', line 26

def value_from_config(name)
  if @config_hash.has_key?(name)
    yield(@config_hash[name])
  end
end