Sha256: 408fa6d99092ce4a22cf0102f51429b40f4130c45c9dda4d5e74d1bffbf1fb55

Contents?: true

Size: 1.15 KB

Versions: 1

Compression:

Stored size: 1.15 KB

Contents

# frozen_string_literal: true

module Tataru
  module Representations
    # internal representation of resources
    class ResourceRepresentation < Representation
      attr_reader :name, :properties, :desc

      def initialize(name, desc, properties)
        @name = name
        @properties = properties
        @desc = desc
        check_late_deletability!
      end

      def check_late_deletability!
        return unless @desc.delete_at_end? && !@desc.needs_remote_id?

        raise 'must need remote id if deletes at end'
      end

      def check_required_fields!
        @desc.required_fields.each do |field|
          next if @properties.key? field

          raise "Required field '#{field}' not provided in '#{@name}'"
        end
      end

      def respond_to_missing?(name, *_args)
        true if @desc.output_fields.include? name
      end

      def remote_id
        OutputRepresentation.new(@name, :remote_id)
      end

      def method_missing(name, *args, &block)
        return super unless @desc.output_fields.include? name

        OutputRepresentation.new(@name, name)
      end

      def dependencies
        [@name]
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
tataru-0.2.0 lib/tataru/representations/resource_representation.rb