Class: KubeDSL::Ref

Inherits:
Object
  • Object
show all
Includes:
StringHelpers
Defined in:
lib/kube-dsl/ref.rb

Direct Known Subclasses

ExternalRef

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from StringHelpers

#capitalize, #underscore

Constructor Details

#initialize(str, ruby_namespace_prefix, autoload_prefix, inflector, schema_dir) ⇒ Ref

Returns a new instance of Ref.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/kube-dsl/ref.rb', line 8

def initialize(str, ruby_namespace_prefix, autoload_prefix, inflector, schema_dir)
  @str = str
  @ruby_namespace_prefix = ruby_namespace_prefix
  @autoload_prefix = autoload_prefix
  @inflector = inflector
  @schema_dir = schema_dir

  ns, v, k = str.split('.').last(3)

  if ns == 'api' && v == 'resource'
    @kind = k
  elsif ns == 'core'
    @kind = k
    @version = v
  else
    @kind = k
    @namespace = ns
    @version = v
  end
end

Instance Attribute Details

#autoload_prefixObject (readonly)

Returns the value of attribute autoload_prefix.



6
7
8
# File 'lib/kube-dsl/ref.rb', line 6

def autoload_prefix
  @autoload_prefix
end

#inflectorObject (readonly)

Returns the value of attribute inflector.



5
6
7
# File 'lib/kube-dsl/ref.rb', line 5

def inflector
  @inflector
end

#kindObject (readonly)

Returns the value of attribute kind.



5
6
7
# File 'lib/kube-dsl/ref.rb', line 5

def kind
  @kind
end

#namespaceObject (readonly)

Returns the value of attribute namespace.



5
6
7
# File 'lib/kube-dsl/ref.rb', line 5

def namespace
  @namespace
end

#ruby_namespace_prefixObject (readonly)

Returns the value of attribute ruby_namespace_prefix.



6
7
8
# File 'lib/kube-dsl/ref.rb', line 6

def ruby_namespace_prefix
  @ruby_namespace_prefix
end

#schema_dirObject (readonly)

Returns the value of attribute schema_dir.



5
6
7
# File 'lib/kube-dsl/ref.rb', line 5

def schema_dir
  @schema_dir
end

#strObject (readonly)

Returns the value of attribute str.



5
6
7
# File 'lib/kube-dsl/ref.rb', line 5

def str
  @str
end

#versionObject (readonly)

Returns the value of attribute version.



5
6
7
# File 'lib/kube-dsl/ref.rb', line 5

def version
  @version
end

Instance Method Details

#documentObject



33
34
35
# File 'lib/kube-dsl/ref.rb', line 33

def document
  JSON.parse(File.read(filename))
end

#metaObject



29
30
31
# File 'lib/kube-dsl/ref.rb', line 29

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

#object?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/kube-dsl/ref.rb', line 37

def object?
  document.include?('properties')
end

#ruby_autoload_pathObject



50
51
52
53
54
55
56
57
58
# File 'lib/kube-dsl/ref.rb', line 50

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

#ruby_namespaceObject



41
42
43
44
45
46
47
48
# File 'lib/kube-dsl/ref.rb', line 41

def ruby_namespace
  @ruby_namespace ||= begin
    [*ruby_namespace_prefix].tap do |mods|
      mods << capitalize(namespace) if namespace
      mods << capitalize(version) if version
    end
  end
end