Class: KubeDSL::Builder
- Inherits:
-
Object
- Object
- KubeDSL::Builder
- Defined in:
- lib/kube-dsl/builder.rb
Instance Attribute Summary collapse
-
#autoload_prefix ⇒ Object
readonly
Returns the value of attribute autoload_prefix.
-
#dsl_namespace ⇒ Object
readonly
Returns the value of attribute dsl_namespace.
-
#entrypoint_namespace ⇒ Object
readonly
Returns the value of attribute entrypoint_namespace.
-
#inflector ⇒ Object
readonly
Returns the value of attribute inflector.
-
#output_dir ⇒ Object
readonly
Returns the value of attribute output_dir.
-
#resolvers ⇒ Object
readonly
Returns the value of attribute resolvers.
-
#schema_dir ⇒ Object
readonly
Returns the value of attribute schema_dir.
-
#serialize_handlers ⇒ Object
readonly
Returns the value of attribute serialize_handlers.
Instance Method Summary collapse
- #each_autoload_file(&block) ⇒ Object
- #each_resource ⇒ Object
- #each_resource_file ⇒ Object
- #entrypoint(&block) ⇒ Object
-
#initialize(schema_dir:, output_dir:, autoload_prefix:, inflector:, dsl_namespace:, entrypoint_namespace:) ⇒ Builder
constructor
A new instance of Builder.
- #parse_ref(ref_str) ⇒ Object
- #register_resolver(*prefixes, &resolver) ⇒ Object
- #register_serialize_handler(namespace, version, kind, field, &block) ⇒ Object
- #resource_from_ref(ref) ⇒ Object
Constructor Details
#initialize(schema_dir:, output_dir:, autoload_prefix:, inflector:, dsl_namespace:, entrypoint_namespace:) ⇒ Builder
Returns a new instance of Builder.
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/kube-dsl/builder.rb', line 11 def initialize(schema_dir:, output_dir:, autoload_prefix:, inflector:, dsl_namespace:, entrypoint_namespace:) @schema_dir = schema_dir @output_dir = output_dir @autoload_prefix = autoload_prefix @inflector = inflector @dsl_namespace = dsl_namespace @entrypoint_namespace = entrypoint_namespace @resolvers = {} @serialize_handlers = [] @resources = nil end |
Instance Attribute Details
#autoload_prefix ⇒ Object (readonly)
Returns the value of attribute autoload_prefix.
7 8 9 |
# File 'lib/kube-dsl/builder.rb', line 7 def autoload_prefix @autoload_prefix end |
#dsl_namespace ⇒ Object (readonly)
Returns the value of attribute dsl_namespace.
8 9 10 |
# File 'lib/kube-dsl/builder.rb', line 8 def dsl_namespace @dsl_namespace end |
#entrypoint_namespace ⇒ Object (readonly)
Returns the value of attribute entrypoint_namespace.
8 9 10 |
# File 'lib/kube-dsl/builder.rb', line 8 def entrypoint_namespace @entrypoint_namespace end |
#inflector ⇒ Object (readonly)
Returns the value of attribute inflector.
9 10 11 |
# File 'lib/kube-dsl/builder.rb', line 9 def inflector @inflector end |
#output_dir ⇒ Object (readonly)
Returns the value of attribute output_dir.
7 8 9 |
# File 'lib/kube-dsl/builder.rb', line 7 def output_dir @output_dir end |
#resolvers ⇒ Object (readonly)
Returns the value of attribute resolvers.
9 10 11 |
# File 'lib/kube-dsl/builder.rb', line 9 def resolvers @resolvers end |
#schema_dir ⇒ Object (readonly)
Returns the value of attribute schema_dir.
7 8 9 |
# File 'lib/kube-dsl/builder.rb', line 7 def schema_dir @schema_dir end |
#serialize_handlers ⇒ Object (readonly)
Returns the value of attribute serialize_handlers.
9 10 11 |
# File 'lib/kube-dsl/builder.rb', line 9 def serialize_handlers @serialize_handlers end |
Instance Method Details
#each_autoload_file(&block) ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/kube-dsl/builder.rb', line 47 def each_autoload_file(&block) return to_enum(__method__) unless block each_autoload_file_helper( autoload_map[:root], [], &block ) end |
#each_resource ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/kube-dsl/builder.rb', line 70 def each_resource return to_enum(__method__) unless block_given? load_resources unless @resources @resources.each do |res| # "External" resources are ones that live outside the current # schema, i.e. k8s resources like ObjectMeta that other # k8s-compatible schemas depend on. # # Resources can be "empty" if they contain no properties. This # usually happens for resources that are really just aliases # for basic types like integer and string. The k8s' Duration # object is a good example. It's just an alias for string. yield res if !res.external? && !res.empty? end end |
#each_resource_file ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/kube-dsl/builder.rb', line 35 def each_resource_file return to_enum(__method__) unless block_given? each_resource do |res| yield File.join(output_dir, res.ref.ruby_autoload_path), res end end |
#entrypoint(&block) ⇒ Object
43 44 45 |
# File 'lib/kube-dsl/builder.rb', line 43 def entrypoint(&block) EntrypointBuilder.new(self, &block) end |
#parse_ref(ref_str) ⇒ Object
66 67 68 |
# File 'lib/kube-dsl/builder.rb', line 66 def parse_ref(ref_str) Ref.new(ref_str, dsl_namespace, inflector, schema_dir, autoload_prefix, serialize_handlers) end |
#register_resolver(*prefixes, &resolver) ⇒ Object
23 24 25 26 27 |
# File 'lib/kube-dsl/builder.rb', line 23 def register_resolver(*prefixes, &resolver) prefixes.each do |prefix| @resolvers[prefix] = resolver end end |
#register_serialize_handler(namespace, version, kind, field, &block) ⇒ Object
29 30 31 32 33 |
# File 'lib/kube-dsl/builder.rb', line 29 def register_serialize_handler(namespace, version, kind, field, &block) @serialize_handlers << SerializeHandler.new( namespace, version, kind, field, &block ) end |
#resource_from_ref(ref) ⇒ Object
55 56 57 58 59 60 61 62 63 64 |
# File 'lib/kube-dsl/builder.rb', line 55 def resource_from_ref(ref) if res = resource_cache[ref.str] return res end res = resource_cache[ref.str] = ref. add_doc_to_resource(res, ref.document) res end |