Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DSL: change container_type to extensible container #6068

Merged
merged 1 commit into from
Sep 8, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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