Class: KubeDSL::Ref
- Inherits:
-
Object
- Object
- KubeDSL::Ref
- Includes:
- StringHelpers
- Defined in:
- lib/kube-dsl/ref.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#autoload_prefix ⇒ Object
readonly
Returns the value of attribute autoload_prefix.
-
#inflector ⇒ Object
readonly
Returns the value of attribute inflector.
-
#kind ⇒ Object
readonly
Returns the value of attribute kind.
-
#namespace ⇒ Object
readonly
Returns the value of attribute namespace.
-
#ruby_namespace_prefix ⇒ Object
readonly
Returns the value of attribute ruby_namespace_prefix.
-
#schema_dir ⇒ Object
readonly
Returns the value of attribute schema_dir.
-
#str ⇒ Object
readonly
Returns the value of attribute str.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Instance Method Summary collapse
- #document ⇒ Object
-
#initialize(str, ruby_namespace_prefix, autoload_prefix, inflector, schema_dir) ⇒ Ref
constructor
A new instance of Ref.
- #meta ⇒ Object
- #object? ⇒ Boolean
- #ruby_autoload_path ⇒ Object
- #ruby_namespace ⇒ Object
Methods included from StringHelpers
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_prefix ⇒ Object (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 |
#inflector ⇒ Object (readonly)
Returns the value of attribute inflector.
5 6 7 |
# File 'lib/kube-dsl/ref.rb', line 5 def inflector @inflector end |
#kind ⇒ Object (readonly)
Returns the value of attribute kind.
5 6 7 |
# File 'lib/kube-dsl/ref.rb', line 5 def kind @kind end |
#namespace ⇒ Object (readonly)
Returns the value of attribute namespace.
5 6 7 |
# File 'lib/kube-dsl/ref.rb', line 5 def namespace @namespace end |
#ruby_namespace_prefix ⇒ Object (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_dir ⇒ Object (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 |
#str ⇒ Object (readonly)
Returns the value of attribute str.
5 6 7 |
# File 'lib/kube-dsl/ref.rb', line 5 def str @str end |
#version ⇒ Object (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
#document ⇒ Object
33 34 35 |
# File 'lib/kube-dsl/ref.rb', line 33 def document JSON.parse(File.read(filename)) end |
#meta ⇒ Object
29 30 31 |
# File 'lib/kube-dsl/ref.rb', line 29 def ||= ResourceMeta.new(self, inflector) end |
#object? ⇒ Boolean
37 38 39 |
# File 'lib/kube-dsl/ref.rb', line 37 def object? document.include?('properties') end |
#ruby_autoload_path ⇒ Object
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_namespace ⇒ Object
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 |