Skip to content

Commit

Permalink
Merge pull request #6068 from rolandwalker/container_dsl
Browse files Browse the repository at this point in the history
DSL: change container_type to extensible container
  • Loading branch information
rolandwalker committed Sep 8, 2014
2 parents fea75ed + ca21928 commit b8523e2
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
20 changes: 20 additions & 0 deletions lib/cask/dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
]
Expand Down
26 changes: 26 additions & 0 deletions lib/cask/dsl/container.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit b8523e2

Please sign in to comment.