Skip to content

Commit

Permalink
Merge pull request #4845 from rolandwalker/dsl_aliases
Browse files Browse the repository at this point in the history
DSL: forward-compatible synonyms (WIP)
  • Loading branch information
rolandwalker committed Jun 28, 2014
2 parents 2c06def + 8ab9bae commit 743c0cf
Showing 1 changed file with 29 additions and 7 deletions.
36 changes: 29 additions & 7 deletions lib/cask/dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,24 @@ def caveats(*string, &block)
end
end

# This hash is transitional. Each of these stanzas will
# ultimately either be removed or upgraded with its own
# unique semantics.
STANZA_ALIASES = {
:pkg => :install, # to remove
:app => :link, # to upgrade
:suite => :link, # to upgrade
:preflight => :before_install, # to remove
:postflight => :after_install, # to remove
:uninstall_preflight => :before_uninstall, # to remove
:uninstall_postflight => :after_uninstall, # to remove
}

def self.ordinary_artifact_types
@@ordinary_artifact_types ||= [
:link,
:app,
:suite,
:prefpane,
:qlplugin,
:font,
Expand All @@ -151,16 +166,18 @@ def self.ordinary_artifact_types
:binary,
:input_method,
:screen_saver,
:install,
:install, # deprecated
:pkg,
]
end

installable_artifact_types = ordinary_artifact_types
installable_artifact_types.push :caskroom_only

installable_artifact_types.each do |type|
resolved_type = STANZA_ALIASES.key?(type) ? STANZA_ALIASES[type] : type
define_method(type) do |*args|
artifacts[type] << args
artifacts[resolved_type] << args
end
end

Expand All @@ -177,15 +194,20 @@ def self.ordinary_artifact_types
end

ARTIFACT_BLOCK_TYPES = [
:after_install,
:after_uninstall,
:before_install,
:before_uninstall,
:after_install, # deprecated
:after_uninstall, # deprecated
:before_install, # deprecated
:before_uninstall, # deprecated
:preflight,
:postflight,
:uninstall_preflight,
:uninstall_postflight,
]

ARTIFACT_BLOCK_TYPES.each do |type|
resolved_type = STANZA_ALIASES.key?(type) ? STANZA_ALIASES[type] : type
define_method(type) do |&block|
artifacts[type] << block
artifacts[resolved_type] << block
end
end

Expand Down

0 comments on commit 743c0cf

Please sign in to comment.