Sha256: c081ac48e7d143a9aa1c7b168094b1eb21a44ad22b4de292a41a7e0614ab122f

Contents?: true

Size: 847 Bytes

Versions: 2

Compression:

Stored size: 847 Bytes

Contents

module Syncano
  class Schema
    class ResourceDefinition
      attr_accessor :attributes
      attr_accessor :name

      def initialize(name, raw_defitnition)
        @raw_definition = raw_defitnition

        delete_colliding_links

        self.name = name

        self.attributes = raw_defitnition[:attributes].map do |name, raw_attribute_definition|
          Syncano::Schema::AttributeDefinition.new name, raw_attribute_definition
        end
      end

      def [](key)
        @raw_definition[key]
      end

      private

      def delete_colliding_links
        @raw_definition[:attributes].each do |k, v|
          if @raw_definition[:associations]['links']
            @raw_definition[:associations]['links'].delete_if do |link|
              link['name'] == k
            end
          end
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
syncano-4.0.0.alpha1 lib/syncano/schema/resource_definition.rb
syncano-4.0.0.alpha lib/syncano/schema/resource_definition.rb