Sha256: 4555aa00c1221fe0b0d54da710bd49fbc6f785faafb90c0a374e33fb70c834a0

Contents?: true

Size: 893 Bytes

Versions: 3

Compression:

Stored size: 893 Bytes

Contents

module Syncano
  class Schema
    class EndpointsWhitelist
      include Enumerable

      class SupportedDefinitionPredicate
        attr_accessor :definition

        def initialize(definition)
          self.definition = definition
        end

        def call
          path =~ /\A\/v1\/instances/ && path !~ /invitation/
        end

        private

        def path
          definition[:collection] && definition[:collection][:path] ||
            definition[:member] && definition[:member][:path]
        end
      end

      SUPPORTED_DEFINITIONS = -> (definition) {
        SupportedDefinitionPredicate.new(definition).call
      }

      def initialize(schema)
        @definition = schema.definition
      end

      def each(&block)
        @definition.select { |_name, definition|
          SUPPORTED_DEFINITIONS === definition
        }.each &block
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

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