Sha256: fd879c6d49038fe630a0053c1c66a56d4d36e3d640843a34cda8b34acef61dec

Contents?: true

Size: 1016 Bytes

Versions: 26

Compression:

Stored size: 1016 Bytes

Contents

require_relative "type_declaration"

module Foobara
  module Manifest
    class Attributes < TypeDeclaration
      optional_keys :required, :defaults

      alias attributes_manifest relevant_manifest

      def required?(attribute_name)
        required = DataPath.value_at(:required, attributes_manifest)

        if required
          required.include?(attribute_name.to_sym) || required.include?(attribute_name.to_s)
        end
      end

      def default_for(attribute_name)
        DataPath.value_at([:defaults, attribute_name], attributes_manifest)
      end

      def attribute_declarations
        element_type_declarations.keys.to_h do |attribute_name|
          [
            attribute_name.to_sym,
            TypeDeclaration.new(root_manifest, [*path, :element_type_declarations, attribute_name])
          ]
        end
      end

      def empty?
        attribute_declarations.empty?
      end

      def attribute_names
        attribute_declarations.keys.map(&:to_s)
      end
    end
  end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
foobara-0.0.26 projects/manifest/src/foobara/manifest/attributes.rb
foobara-0.0.25 projects/manifest/src/foobara/manifest/attributes.rb
foobara-0.0.24 projects/manifest/src/foobara/manifest/attributes.rb
foobara-0.0.23 projects/manifest/src/foobara/manifest/attributes.rb
foobara-0.0.22 projects/manifest/src/foobara/manifest/attributes.rb
foobara-0.0.21 projects/manifest/src/foobara/manifest/attributes.rb
foobara-0.0.20 projects/manifest/src/foobara/manifest/attributes.rb
foobara-0.0.19 projects/manifest/src/foobara/manifest/attributes.rb
foobara-0.0.18 projects/manifest/src/foobara/manifest/attributes.rb
foobara-0.0.17 projects/manifest/src/foobara/manifest/attributes.rb
foobara-0.0.16 projects/manifest/src/foobara/manifest/attributes.rb
foobara-0.0.15 projects/manifest/src/foobara/manifest/attributes.rb
foobara-0.0.14 projects/manifest/src/foobara/manifest/attributes.rb
foobara-0.0.13 projects/manifest/src/foobara/manifest/attributes.rb
foobara-0.0.12 projects/manifest/src/foobara/manifest/attributes.rb
foobara-0.0.11 projects/manifest/src/foobara/manifest/attributes.rb
foobara-0.0.10 projects/manifest/src/foobara/manifest/attributes.rb
foobara-0.0.9 projects/manifest/src/foobara/manifest/attributes.rb
foobara-0.0.8 projects/manifest/src/foobara/manifest/attributes.rb
foobara-0.0.7 projects/manifest/src/foobara/manifest/attributes.rb