Sha256: 097e8376a9f71b77cf3248b22695f7640c4a19f81a7d664714bfeb6800a5c7b9

Contents?: true

Size: 897 Bytes

Versions: 38

Compression:

Stored size: 897 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.nil? || 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

38 entries across 38 versions & 1 rubygems

Version Path
buildkite-builder-4.1.2 lib/buildkite/builder/data.rb
buildkite-builder-4.1.1 lib/buildkite/builder/data.rb
buildkite-builder-4.1.0 lib/buildkite/builder/data.rb
buildkite-builder-4.0.0 lib/buildkite/builder/data.rb
buildkite-builder-3.9.0 lib/buildkite/builder/data.rb
buildkite-builder-3.8.3 lib/buildkite/builder/data.rb
buildkite-builder-3.8.2 lib/buildkite/builder/data.rb
buildkite-builder-3.8.1 lib/buildkite/builder/data.rb
buildkite-builder-3.8.0 lib/buildkite/builder/data.rb
buildkite-builder-3.7.0 lib/buildkite/builder/data.rb
buildkite-builder-3.6.0 lib/buildkite/builder/data.rb
buildkite-builder-3.5.0 lib/buildkite/builder/data.rb
buildkite-builder-3.4.0 lib/buildkite/builder/data.rb
buildkite-builder-3.3.2 lib/buildkite/builder/data.rb
buildkite-builder-3.3.1 lib/buildkite/builder/data.rb
buildkite-builder-3.3.0 lib/buildkite/builder/data.rb
buildkite-builder-3.2.0 lib/buildkite/builder/data.rb
buildkite-builder-3.1.0 lib/buildkite/builder/data.rb