Merge pull request #2519 from reitermarkus/validate-container-type

Validate `container :type`.
This commit is contained in:
Markus Reiter 2017-04-22 12:53:17 +02:00 committed by GitHub
commit 44232ab044
2 changed files with 8 additions and 3 deletions

View File

@ -61,7 +61,7 @@ module Hbc
begin
const_get(type.to_s.split("_").map(&:capitalize).join)
rescue NameError
false
nil
end
end
end

View File

@ -1,3 +1,5 @@
require "hbc/container"
module Hbc
class DSL
class Container
@ -13,9 +15,12 @@ module Hbc
@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)
send(:"#{key}=", value)
end
return if type.nil?
return unless Hbc::Container.from_type(type).nil?
raise "invalid container type: #{type.inspect}"
end
def to_yaml