Sha256: b614e9a41c405bf4d3b6b5f0ec897b7982a15881386fb7f2d564797ec7559019

Contents?: true

Size: 870 Bytes

Versions: 10

Compression:

Stored size: 870 Bytes

Contents

# frozen_string_literal: true

require 'media_types/scheme/rules'
require 'media_types/scheme/rules_exhausted_guard'

module MediaTypes
  class Scheme
    class Links
      def initialize
        self.links = Rules.new(allow_empty: false, expected_type: ::Hash)
      end

      def link(key, allow_nil: false, optional: false, &block)
        links.add(
          key,
          Scheme.new do
            attribute :href, String, allow_nil: allow_nil
            instance_exec(&block) if block_given?
          end,
          optional: optional
        )

        self
      end

      def validate!(output, options, **_opts)
        RulesExhaustedGuard.call(output, options, rules: links)
      end

      def inspect
        "[Scheme::Links #{links.keys}]"
      end

      private

      attr_accessor :links
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
media_types-2.0.1 lib/media_types/scheme/links.rb
media_types-2.0.0 lib/media_types/scheme/links.rb
media_types-1.0.0 lib/media_types/scheme/links.rb
media_types-0.6.2 lib/media_types/scheme/links.rb
media_types-0.6.1 lib/media_types/scheme/links.rb
media_types-0.6.0 lib/media_types/scheme/links.rb
media_types-0.5.5 lib/media_types/scheme/links.rb
media_types-0.5.4 lib/media_types/scheme/links.rb
media_types-0.5.3 lib/media_types/scheme/links.rb
media_types-0.5.2 lib/media_types/scheme/links.rb