Skip to content

Commit

Permalink
Merge pull request #3141 from reitermarkus/single-artifacts
Browse files Browse the repository at this point in the history
Make artifacts singular.
  • Loading branch information
reitermarkus authored Sep 11, 2017
2 parents 5bcce73 + b0c98ba commit f3ec40d
Show file tree
Hide file tree
Showing 44 changed files with 598 additions and 545 deletions.
9 changes: 3 additions & 6 deletions Library/Homebrew/cask/lib/hbc/artifact.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ module Artifact
# We want to extract nested containers before we
# handle any other artifacts.
#
TYPES = [
CLASSES = [
PreflightBlock,
Uninstall,
NestedContainer,
Expand All @@ -60,12 +60,9 @@ module Artifact
Zap,
].freeze

def self.for_cask(cask, options = {})
def self.for_cask(cask)
odebug "Determining which artifacts are present in Cask #{cask}"

TYPES
.select { |klass| klass.me?(cask) }
.map { |klass| klass.new(cask, options) }
CLASSES.flat_map { |klass| klass.for_cask(cask) }
end
end
end
Original file line number Diff line number Diff line change
@@ -1,34 +1,28 @@
module Hbc
module Artifact
class Base
class AbstractArtifact
extend Predicable

def self.artifact_name
@artifact_name ||= name.sub(/^.*:/, "").gsub(/(.)([A-Z])/, '\1_\2').downcase
def self.english_name
@english_name ||= name.sub(/^.*:/, "").gsub(/(.)([A-Z])/, '\1 \2')
end

def self.artifact_english_name
@artifact_english_name ||= name.sub(/^.*:/, "").gsub(/(.)([A-Z])/, '\1 \2')
def self.english_article
@english_article ||= (english_name =~ /^[aeiou]/i) ? "an" : "a"
end

def self.artifact_english_article
@artifact_english_article ||= (artifact_english_name =~ /^[aeiou]/i) ? "an" : "a"
def self.dsl_key
@dsl_key ||= name.sub(/^.*:/, "").gsub(/(.)([A-Z])/, '\1_\2').downcase.to_sym
end

def self.artifact_dsl_key
@artifact_dsl_key ||= artifact_name.to_sym
def self.dirmethod
@dirmethod ||= "#{dsl_key}dir".to_sym
end

def self.artifact_dirmethod
@artifact_dirmethod ||= "#{artifact_name}dir".to_sym
def self.for_cask(cask)
cask.artifacts[dsl_key].to_a
end

def self.me?(cask)
cask.artifacts[artifact_dsl_key].any?
end

attr_reader :force

# TODO: this sort of logic would make more sense in dsl.rb, or a
# constructor called from dsl.rb, so long as that isn't slow.
def self.read_script_arguments(arguments, stanza, default_arguments = {}, override_arguments = {}, key = nil)
Expand Down Expand Up @@ -63,17 +57,14 @@ def self.read_script_arguments(arguments, stanza, default_arguments = {}, overri
[executable, arguments]
end

def summary
{}
end
attr_reader :cask

attr_predicate :force?, :verbose?

def initialize(cask, command: SystemCommand, force: false, verbose: false)
def initialize(cask)
@cask = cask
@command = command
@force = force
@verbose = verbose
end

def to_s
"#{summarize} (#{self.class.english_name})"
end
end
end
Expand Down
42 changes: 25 additions & 17 deletions Library/Homebrew/cask/lib/hbc/artifact/abstract_flight_block.rb
Original file line number Diff line number Diff line change
@@ -1,39 +1,47 @@
require "hbc/artifact/base"
require "hbc/artifact/abstract_artifact"

module Hbc
module Artifact
class AbstractFlightBlock < Base
def self.artifact_dsl_key
class AbstractFlightBlock < AbstractArtifact
def self.dsl_key
super.to_s.sub(/_block$/, "").to_sym
end

def self.uninstall_artifact_dsl_key
artifact_dsl_key.to_s.prepend("uninstall_").to_sym
def self.uninstall_dsl_key
dsl_key.to_s.prepend("uninstall_").to_sym
end

def self.class_for_dsl_key(dsl_key)
Object.const_get("Hbc::DSL::#{dsl_key.to_s.split("_").collect(&:capitalize).join}")
def self.for_cask(cask)
[dsl_key, uninstall_dsl_key].flat_map do |key|
[*cask.artifacts[key]].map { |block| new(cask, key => block) }
end
end

def self.me?(cask)
cask.artifacts[artifact_dsl_key].any? ||
cask.artifacts[uninstall_artifact_dsl_key].any?
attr_reader :directives

def initialize(cask, **directives)
super(cask)
@directives = directives
end

def install_phase
abstract_phase(self.class.artifact_dsl_key)
def install_phase(**)
abstract_phase(self.class.dsl_key)
end

def uninstall_phase
abstract_phase(self.class.uninstall_artifact_dsl_key)
def uninstall_phase(**)
abstract_phase(self.class.uninstall_dsl_key)
end

private

def class_for_dsl_key(dsl_key)
namespace = self.class.name.to_s.sub(/::.*::.*$/, "")
self.class.const_get("#{namespace}::DSL::#{dsl_key.to_s.split("_").collect(&:capitalize).join}")
end

def abstract_phase(dsl_key)
@cask.artifacts[dsl_key].each do |block|
self.class.class_for_dsl_key(dsl_key).new(@cask).instance_eval(&block)
end
return if (block = directives[dsl_key]).nil?
class_for_dsl_key(dsl_key).new(cask).instance_eval(&block)
end
end
end
Expand Down
Loading

0 comments on commit f3ec40d

Please sign in to comment.