Class: KubeDSL::InlineRef

Inherits:
Object
  • Object
show all
Defined in:
lib/kube-dsl/inline_ref.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, document, parent_ref, serialize_handlers) ⇒ InlineRef

Returns a new instance of InlineRef.



6
7
8
9
10
11
# File 'lib/kube-dsl/inline_ref.rb', line 6

def initialize(name, document, parent_ref, serialize_handlers)
  @name = name
  @document = document
  @parent_ref = parent_ref
  @serialize_handlers = serialize_handlers
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, **kwargs, &block) ⇒ Object



13
14
15
# File 'lib/kube-dsl/inline_ref.rb', line 13

def method_missing(method_name, *args, **kwargs, &block)
  parent_ref.send(method_name, *args, **kwargs, &block)
end

Instance Attribute Details

#documentObject (readonly)

Returns the value of attribute document.



4
5
6
# File 'lib/kube-dsl/inline_ref.rb', line 4

def document
  @document
end

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/kube-dsl/inline_ref.rb', line 4

def name
  @name
end

#parent_refObject (readonly)

Returns the value of attribute parent_ref.



4
5
6
# File 'lib/kube-dsl/inline_ref.rb', line 4

def parent_ref
  @parent_ref
end

#serialize_handlersObject (readonly)

Returns the value of attribute serialize_handlers.



4
5
6
# File 'lib/kube-dsl/inline_ref.rb', line 4

def serialize_handlers
  @serialize_handlers
end

Instance Method Details

#inline?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/kube-dsl/inline_ref.rb', line 21

def inline?
  true
end

#kindObject



29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/kube-dsl/inline_ref.rb', line 29

def kind
  ''.tap do |result|
    current_ref = self

    while current_ref.inline?
      # this is String#prepend
      result.prepend(capitalize(current_ref.name))
      current_ref = current_ref.parent_ref
    end

    result.prepend(current_ref.kind)
  end
end

#metaObject



25
26
27
# File 'lib/kube-dsl/inline_ref.rb', line 25

def meta
  @meta ||= ResourceMeta.new(self, inflector, serialize_handlers)
end

#respond_to_missing?(method_name) ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/kube-dsl/inline_ref.rb', line 17

def respond_to_missing?(method_name)
  parent_ref.respond_to?(method_name)
end

#ruby_autoload_pathObject



47
48
49
50
51
52
53
54
55
# File 'lib/kube-dsl/inline_ref.rb', line 47

def ruby_autoload_path
  @ruby_autoload_path ||= File.join(
    [autoload_prefix].tap do |path|
      path << underscore(namespace) if namespace
      path << underscore(version) if version
      path << shorten("#{underscore(kind)}.rb")
    end
  )
end

#shorten(filename) ⇒ Object



57
58
59
60
61
62
63
64
# File 'lib/kube-dsl/inline_ref.rb', line 57

def shorten(filename)
  return filename if filename.size <= 100

  digest = Digest::MD5.hexdigest(filename)[0...8]
  extname = File.extname(filename)

  "#{filename.chomp(extname)[0...(100 - extname.size - digest.size - 1)]}_#{digest}#{extname}"
end

#strObject



43
44
45
# File 'lib/kube-dsl/inline_ref.rb', line 43

def str
  @str ||= "#{parent_ref.str}.#{name}"
end