2016-09-24 13:52:43 +02:00
|
|
|
module Hbc
|
|
|
|
class DSL
|
|
|
|
class Container
|
|
|
|
VALID_KEYS = Set.new [
|
|
|
|
:type,
|
|
|
|
:nested,
|
|
|
|
]
|
2016-08-18 22:11:42 +03:00
|
|
|
|
2016-09-24 13:52:43 +02:00
|
|
|
attr_accessor(*VALID_KEYS)
|
|
|
|
attr_accessor :pairs
|
2016-08-18 22:11:42 +03:00
|
|
|
|
2016-09-24 13:52:43 +02:00
|
|
|
def initialize(pairs = {})
|
|
|
|
@pairs = pairs
|
|
|
|
pairs.each do |key, value|
|
|
|
|
raise "invalid container key: '#{key.inspect}'" unless VALID_KEYS.include?(key)
|
|
|
|
writer_method = "#{key}=".to_sym
|
|
|
|
send(writer_method, value)
|
|
|
|
end
|
|
|
|
end
|
2016-08-18 22:11:42 +03:00
|
|
|
|
2016-09-24 13:52:43 +02:00
|
|
|
def to_yaml
|
|
|
|
@pairs.to_yaml
|
|
|
|
end
|
2016-08-18 22:11:42 +03:00
|
|
|
|
2016-09-24 13:52:43 +02:00
|
|
|
def to_s
|
|
|
|
@pairs.inspect
|
|
|
|
end
|
|
|
|
end
|
2016-08-18 22:11:42 +03:00
|
|
|
end
|
|
|
|
end
|