Sha256: 2af74ca6abfe41084b64e42265a44292b02d1b7b6c094f82a3366dc8d27cbac6

Contents?: true

Size: 1001 Bytes

Versions: 3

Compression:

Stored size: 1001 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

      def top_level?
        @raw_definition[:collection].present? &&
          @raw_definition[:collection][:path].scan(/\{([^}]+)\}/).empty?
      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

3 entries across 3 versions & 1 rubygems

Version Path
syncano-4.0.0.alpha4 lib/syncano/schema/resource_definition.rb
syncano-4.0.0.alpha3 lib/syncano/schema/resource_definition.rb
syncano-4.0.0.alpha2 lib/syncano/schema/resource_definition.rb