Class: Hbc::DSL::StanzaProxy

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, &resolver) ⇒ StanzaProxy

Returns a new instance of StanzaProxy



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

def initialize(type, &resolver)
  @type = type
  @resolver = resolver
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object



30
31
32
33
34
35
36
# File 'Library/Homebrew/cask/lib/hbc/dsl/stanza_proxy.rb', line 30

def method_missing(method, *args)
  if method != :to_ary
    @resolver.call.send(method, *args)
  else
    super
  end
end

Instance Attribute Details

#typeObject (readonly)

Returns the value of attribute type



4
5
6
# File 'Library/Homebrew/cask/lib/hbc/dsl/stanza_proxy.rb', line 4

def type
  @type
end

Class Method Details

.once(type) ⇒ Object



6
7
8
9
# File 'Library/Homebrew/cask/lib/hbc/dsl/stanza_proxy.rb', line 6

def self.once(type)
  resolved = nil
  new(type) { resolved ||= yield }
end

Instance Method Details

#encode_with(coder) ⇒ Object

Serialization for dumpcask



25
26
27
28
# File 'Library/Homebrew/cask/lib/hbc/dsl/stanza_proxy.rb', line 25

def encode_with(coder)
  coder["type"] = type
  coder["resolved"] = @resolver.call
end

#proxy?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'Library/Homebrew/cask/lib/hbc/dsl/stanza_proxy.rb', line 16

def proxy?
  true
end

#respond_to?(method, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


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

def respond_to?(method, include_private = false)
  return true if [:encode_with, :proxy?, :to_s, :type].include?(method)
  return false if method == :to_ary
  @resolver.call.respond_to?(method, include_private)
end

#respond_to_missing?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'Library/Homebrew/cask/lib/hbc/dsl/stanza_proxy.rb', line 44

def respond_to_missing?(*)
  true
end

#to_sObject



20
21
22
# File 'Library/Homebrew/cask/lib/hbc/dsl/stanza_proxy.rb', line 20

def to_s
  @resolver.call.to_s
end