Class: Cask::Artifact::AbstractArtifact

Inherits:
Object
  • Object
show all
Extended by:
Predicable
Includes:
Comparable
Defined in:
brew/Library/Homebrew/cask/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



119
120
121
# File 'brew/Library/Homebrew/cask/artifact/abstract_artifact.rb', line 119

def initialize(cask)
  @cask = cask
end

Instance Attribute Details

#caskObject (readonly)

Returns the value of attribute cask



117
118
119
# File 'brew/Library/Homebrew/cask/artifact/abstract_artifact.rb', line 117

def cask
  @cask
end

Class Method Details

.dirmethodObject



21
22
23
# File 'brew/Library/Homebrew/cask/artifact/abstract_artifact.rb', line 21

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

.dsl_keyObject



17
18
19
# File 'brew/Library/Homebrew/cask/artifact/abstract_artifact.rb', line 17

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

.english_articleObject



13
14
15
# File 'brew/Library/Homebrew/cask/artifact/abstract_artifact.rb', line 13

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

.english_nameObject



9
10
11
# File 'brew/Library/Homebrew/cask/artifact/abstract_artifact.rb', line 9

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.



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'brew/Library/Homebrew/cask/artifact/abstract_artifact.rb', line 83

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 "Unknown arguments to #{description} -- " \
         "#{unknown_keys.inspect} (ignored). Running " \
         "`brew update; brew 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



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'brew/Library/Homebrew/cask/artifact/abstract_artifact.rb', line 43

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,
    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

#configObject



123
124
125
# File 'brew/Library/Homebrew/cask/artifact/abstract_artifact.rb', line 123

def config
  cask.config
end

#staged_path_join_executable(path) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'brew/Library/Homebrew/cask/artifact/abstract_artifact.rb', line 25

def staged_path_join_executable(path)
  path = Pathname(path)

  absolute_path = if path.absolute?
    path
  else
    cask.staged_path.join(path)
  end

  FileUtils.chmod "+x", absolute_path if absolute_path.exist? && !absolute_path.executable?

  if absolute_path.exist?
    absolute_path
  else
    path
  end
end

#to_sObject



127
128
129
# File 'brew/Library/Homebrew/cask/artifact/abstract_artifact.rb', line 127

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