Class: Hbc::Artifact::AbstractArtifact

Inherits:
Object
  • Object
show all
Extended by:
Predicable
Includes:
Comparable
Defined in:
Library/Homebrew/cask/lib/hbc/artifact/abstract_artifact.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Predicable

attr_predicate

Constructor Details

#initialize(cask) ⇒ AbstractArtifact

Returns a new instance of AbstractArtifact



100
101
102
103
# File 'Library/Homebrew/cask/lib/hbc/artifact/abstract_artifact.rb', line 100

def initialize(cask)
  @cask = cask
  @config = cask.config
end

Instance Attribute Details

#caskObject (readonly)

Returns the value of attribute cask



98
99
100
# File 'Library/Homebrew/cask/lib/hbc/artifact/abstract_artifact.rb', line 98

def cask
  @cask
end

#configObject (readonly)

Returns the value of attribute config



98
99
100
# File 'Library/Homebrew/cask/lib/hbc/artifact/abstract_artifact.rb', line 98

def config
  @config
end

Class Method Details

.dirmethodObject



19
20
21
# File 'Library/Homebrew/cask/lib/hbc/artifact/abstract_artifact.rb', line 19

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

.dsl_keyObject



15
16
17
# File 'Library/Homebrew/cask/lib/hbc/artifact/abstract_artifact.rb', line 15

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

.english_articleObject



11
12
13
# File 'Library/Homebrew/cask/lib/hbc/artifact/abstract_artifact.rb', line 11

def self.english_article
  @english_article ||= (english_name =~ /^[aeiou]/i) ? "an" : "a"
end

.english_nameObject



7
8
9
# File 'Library/Homebrew/cask/lib/hbc/artifact/abstract_artifact.rb', line 7

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

.read_script_arguments(arguments, stanza, default_arguments = {}, override_arguments = {}, key = nil) ⇒ Object

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.


66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'Library/Homebrew/cask/lib/hbc/artifact/abstract_artifact.rb', line 66

def self.read_script_arguments(arguments, stanza, default_arguments = {}, override_arguments = {}, key = nil)
  # TODO: when stanza names are harmonized with class names,
  #       stanza may not be needed as an explicit argument
  description = key ? "#{stanza} #{key.inspect}" : stanza.to_s

  # backward-compatible string value
  arguments = { executable: arguments } if arguments.is_a?(String)

  # key sanity
  permitted_keys = [:args, :input, :executable, :must_succeed, :sudo, :print_stdout, :print_stderr]
  unknown_keys = arguments.keys - permitted_keys
  unless unknown_keys.empty?
    opoo %Q{Unknown arguments to #{description} -- #{unknown_keys.inspect} (ignored). Running "brew update; brew cleanup; brew cask cleanup" will likely fix it.}
  end
  arguments.select! { |k| permitted_keys.include?(k) }

  # key warnings
  override_keys = override_arguments.keys
  ignored_keys = arguments.keys & override_keys
  unless ignored_keys.empty?
    onoe "Some arguments to #{description} will be ignored -- :#{unknown_keys.inspect} (overridden)."
  end

  # extract executable
  executable = arguments.key?(:executable) ? arguments.delete(:executable) : nil

  arguments = default_arguments.merge arguments
  arguments.merge! override_arguments

  [executable, arguments]
end

Instance Method Details

#<=>(other) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'Library/Homebrew/cask/lib/hbc/artifact/abstract_artifact.rb', line 23

def <=>(other)
  return unless other.class < AbstractArtifact
  return 0 if self.class == other.class

  @@sort_order ||= [ # rubocop:disable Style/ClassVars
    PreflightBlock,
    # The `uninstall` stanza should be run first, as it may
    # depend on other artifacts still being installed.
    Uninstall,
    # We want to extract nested containers before we
    # handle any other artifacts.
    NestedContainer,
    Installer,
    [
      App,
      Suite,
      Artifact,
      Colorpicker,
      Prefpane,
      Qlplugin,
      Dictionary,
      Font,
      Service,
      InputMethod,
      InternetPlugin,
      AudioUnitPlugin,
      VstPlugin,
      Vst3Plugin,
      ScreenSaver,
    ],
    # `pkg` should be run before `binary`, so
    # targets are created prior to linking.
    Pkg,
    Binary,
    PostflightBlock,
    Zap,
  ].each_with_index.flat_map { |classes, i| [*classes].map { |c| [c, i] } }.to_h

  (@@sort_order[self.class] <=> @@sort_order[other.class]).to_i
end

#to_sObject



105
106
107
# File 'Library/Homebrew/cask/lib/hbc/artifact/abstract_artifact.rb', line 105

def to_s
  "#{summarize} (#{self.class.english_name})"
end