From ca21928b93382f5dba5e28031559cbb89e2700ef Mon Sep 17 00:00:00 2001 From: Roland Walker Date: Mon, 8 Sep 2014 09:01:46 -0400 Subject: [PATCH] DSL: change container_type to extensible container Late addition to DSL 1.0 (oversight in the roadmap) References: #4688 --- lib/cask/dsl.rb | 20 ++++++++++++++++++++ lib/cask/dsl/container.rb | 26 ++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 lib/cask/dsl/container.rb diff --git a/lib/cask/dsl.rb b/lib/cask/dsl.rb index 2b18ca318054..e4fae3466f68 100644 --- a/lib/cask/dsl.rb +++ b/lib/cask/dsl.rb @@ -11,6 +11,7 @@ module Cask::DSL; end require 'cask/dsl/before_uninstall' require 'cask/dsl/appcast' require 'cask/dsl/conflicts_with' +require 'cask/dsl/container' require 'cask/dsl/depends_on' require 'cask/dsl/gpg' require 'cask/dsl/license' @@ -41,6 +42,8 @@ def conflicts_with; self.class.conflicts_with; end def container_type; self.class.container_type; end + def container; self.class.container; end + def tags; self.class.tags; end def sums; self.class.sums || []; end @@ -95,6 +98,23 @@ def container_type(type=nil) @container_type ||= type end + def container(*args) + if @container and !args.empty? + # todo: remove this constraint, and instead merge multiple container stanzas + raise CaskInvalidError.new(self.title, "'container' stanza may only appear once") + end + @container ||= begin + Cask::DSL::Container.new(*args) unless args.empty? + rescue StandardError => e + raise CaskInvalidError.new(self.title, e) + end + # todo: remove this backwards compatibility section after removing container_type + if @container.formula + @container_type ||= @container.formula + end + @container + end + SYMBOLIC_VERSIONS = Set.new [ :latest, ] diff --git a/lib/cask/dsl/container.rb b/lib/cask/dsl/container.rb new file mode 100644 index 000000000000..4bf7a1c937e1 --- /dev/null +++ b/lib/cask/dsl/container.rb @@ -0,0 +1,26 @@ +class Cask::DSL::Container + + VALID_KEYS = Set.new [ + :type, + ] + + attr_accessor *VALID_KEYS + attr_accessor :pairs + + 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 + + def to_yaml + @pairs.to_yaml + end + + def to_s + @pairs.inspect + end +end