Sha256: 1416ccdc2e54e11c1629c5be2cfcfc7c0dc8d72281f30e6ba5e3d5a4be25c668

Contents?: true

Size: 976 Bytes

Versions: 10

Compression:

Stored size: 976 Bytes

Contents

require 'active_support/concern'
require 'deep_clone'

module Restspec
  module Endpoints
    module HasSchemas
      extend ActiveSupport::Concern

      DEFAULT_ROLES = [:response]
      ROLES = [:response, :payload]

      def schema_roles
        @schema_roles ||= {}
      end

      def add_schema(schema_name, options)
        roles = options.delete(:for) || DEFAULT_ROLES

        roles.each do |role|
          schema_found = Restspec::SchemaStore.fetch(schema_name)

          schema_roles[role] = DeepClone.clone(schema_found)
          schema_roles[role].intention = role
          schema_roles[role].original_schema = schema_found

          if options.any?
            schema_roles[role].extend_with(options)
          end
        end
      end

      def all_schemas
        schema_roles.values
      end

      def remove_schemas
        schema_roles.clear
      end

      def schema_for(role_name)
        schema_roles[role_name]
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
restspec-0.3.2 lib/restspec/endpoints/has_schemas.rb
restspec-0.3.1 lib/restspec/endpoints/has_schemas.rb
restspec-0.3.0 lib/restspec/endpoints/has_schemas.rb
restspec-0.2.6 lib/restspec/endpoints/has_schemas.rb
restspec-0.2.5 lib/restspec/endpoints/has_schemas.rb
restspec-0.2.4 lib/restspec/endpoints/has_schemas.rb
restspec-0.2.3 lib/restspec/endpoints/has_schemas.rb
restspec-0.2.2 lib/restspec/endpoints/has_schemas.rb
restspec-0.2.1 lib/restspec/endpoints/has_schemas.rb
restspec-0.2 lib/restspec/endpoints/has_schemas.rb