Sha256: c07928309ab0981256e42d9eef717cc7b3f86b90d2314b0faa68869ba99613c2

Contents?: true

Size: 1.57 KB

Versions: 33

Compression:

Stored size: 1.57 KB

Contents

module Kubes::Compiler::Dsl::Syntax
  class Resource < Kubes::Compiler::Dsl::Core::Base
    include Kubes::Compiler::Util::Normalize
    include Kubes::Compiler::Shared::Helpers

    fields :apiVersion,  # <string>
           :kind,        # <string>
           :metadata,    # <Object>
           :result,      # <Object>
           :spec         # <Object>

    # kubectl explain deployment.metadata
    fields "annotations:hash",  # <map[string]string>
           "labels:hash",       # <map[string]string>
           :namespace           # <string>

    attr_accessor :kind_from_block

    # top-level of resource is quite common
    def default_result
      data = top.merge(default_top)
      data.deeper_merge!(default_result_append)
      data.deep_stringify_keys!
      HashSqueezer.squeeze(data)
    end

    # Where to set fields for generic kind
    def top
      @top ||= {}
    end

    def default_top
      {
        apiVersion: apiVersion,
        kind: kind,
        metadata: metadata,
        spec: spec,
      }
    end

    # can be overridden by subclasses. IE: secret
    def default_result_append
      {}
    end

    def default_apiVersion
      "v1"
    end

    def default_metadata
      {
        annotations: annotations,
        name: name,
        labels: labels,
        namespace: namespace,
      }
    end

    def default_kind
      return @kind_from_block if @kind_from_block
      normalize_kind(@path)
    end
    alias_method :resource_kind, :default_kind

    # For generic kind
    def field(name, data)
      top.deeper_merge!(name => data)
    end
  end
end

Version data entries

33 entries across 33 versions & 1 rubygems

Version Path
kubes-0.7.0 lib/kubes/compiler/dsl/syntax/resource.rb
kubes-0.6.8 lib/kubes/compiler/dsl/syntax/resource.rb
kubes-0.6.7 lib/kubes/compiler/dsl/syntax/resource.rb
kubes-0.6.6 lib/kubes/compiler/dsl/syntax/resource.rb
kubes-0.6.5 lib/kubes/compiler/dsl/syntax/resource.rb
kubes-0.6.4 lib/kubes/compiler/dsl/syntax/resource.rb
kubes-0.6.3 lib/kubes/compiler/dsl/syntax/resource.rb
kubes-0.6.2 lib/kubes/compiler/dsl/syntax/resource.rb
kubes-0.6.1 lib/kubes/compiler/dsl/syntax/resource.rb
kubes-0.6.0 lib/kubes/compiler/dsl/syntax/resource.rb
kubes-0.5.1 lib/kubes/compiler/dsl/syntax/resource.rb
kubes-0.5.0 lib/kubes/compiler/dsl/syntax/resource.rb
kubes-0.4.7 lib/kubes/compiler/dsl/syntax/resource.rb
kubes-0.4.6 lib/kubes/compiler/dsl/syntax/resource.rb
kubes-0.4.5 lib/kubes/compiler/dsl/syntax/resource.rb
kubes-0.4.4 lib/kubes/compiler/dsl/syntax/resource.rb
kubes-0.4.3 lib/kubes/compiler/dsl/syntax/resource.rb
kubes-0.4.2 lib/kubes/compiler/dsl/syntax/resource.rb
kubes-0.4.1 lib/kubes/compiler/dsl/syntax/resource.rb
kubes-0.4.0 lib/kubes/compiler/dsl/syntax/resource.rb