Sha256: 5f6bf3baf16bb08a73b7d5c3787540b159051ad4c7c1d117174031a749e8ae4f

Contents?: true

Size: 883 Bytes

Versions: 11

Compression:

Stored size: 883 Bytes

Contents

module Buildkite
  module Builder
    class Data
      def initialize
        @data = Hash.new
      end

      def to_definition
        @data.each_with_object({}) do |(key, value), hash|
          value = value.respond_to?(:to_definition) ? value.to_definition : value

          next if value.empty?

          hash[key] = value
        end
      end

      private

      def method_missing(name, *args, &block)
        if name.end_with?('=')
          name = name.to_s.delete_suffix('=').to_sym

          if respond_to_missing?(name)
            raise ArgumentError, "Data already contains key '#{name}'"
          else
            return @data[name] = args.first
          end
        elsif respond_to_missing?(name)
          return @data[name]
        end

        super
      end

      def respond_to_missing?(name, *)
        @data.key?(name)
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
buildkite-builder-3.0.0 lib/buildkite/builder/data.rb
buildkite-builder-2.4.1 lib/buildkite/builder/data.rb
buildkite-builder-2.4.0 lib/buildkite/builder/data.rb
buildkite-builder-2.3.0 lib/buildkite/builder/data.rb
buildkite-builder-2.2.0 lib/buildkite/builder/data.rb
buildkite-builder-2.1.0 lib/buildkite/builder/data.rb
buildkite-builder-2.0.0 lib/buildkite/builder/data.rb
buildkite-builder-2.0.0.beta4 lib/buildkite/builder/data.rb
buildkite-builder-2.0.0.beta3 lib/buildkite/builder/data.rb
buildkite-builder-2.0.0.beta2 lib/buildkite/builder/data.rb
buildkite-builder-2.0.0.beta1 lib/buildkite/builder/data.rb