Class: Hbc::DSL::Caveats

Inherits:
Base
  • Object
show all
Defined in:
Library/Homebrew/cask/lib/hbc/dsl/caveats.rb

Instance Method Summary collapse

Methods inherited from Base

#method_missing, #respond_to_missing?, #system_command

Constructor Details

#initialize(*args) ⇒ Caveats

Returns a new instance of Caveats



11
12
13
14
15
# File 'Library/Homebrew/cask/lib/hbc/dsl/caveats.rb', line 11

def initialize(*args)
  super(*args)
  @built_in_caveats = {}
  @custom_caveats = []
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Hbc::DSL::Base

Instance Method Details

#eval_caveats(&block) ⇒ Object



38
39
40
41
42
43
# File 'Library/Homebrew/cask/lib/hbc/dsl/caveats.rb', line 38

def eval_caveats(&block)
  result = instance_eval(&block)
  return unless result
  return if result == :built_in_caveat
  @custom_caveats << result.to_s.sub(/\s*\Z/, "\n")
end

#puts(*args) ⇒ Object

Override `puts` to collect caveats.



33
34
35
36
# File 'Library/Homebrew/cask/lib/hbc/dsl/caveats.rb', line 33

def puts(*args)
  @custom_caveats += args
  :built_in_caveat
end

#to_sObject



28
29
30
# File 'Library/Homebrew/cask/lib/hbc/dsl/caveats.rb', line 28

def to_s
  (@custom_caveats + @built_in_caveats.values).join("\n")
end