Module: Restspec::Endpoints::HasSchemas

Extended by:
ActiveSupport::Concern
Included in:
Endpoint, Namespace
Defined in:
lib/restspec/endpoints/has_schemas.rb

Constant Summary collapse

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

Instance Method Summary collapse

Instance Method Details

#add_schema(schema_name, options) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/restspec/endpoints/has_schemas.rb', line 16

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

#all_schemasObject



32
33
34
# File 'lib/restspec/endpoints/has_schemas.rb', line 32

def all_schemas
  schema_roles.values
end

#remove_schemasObject



36
37
38
# File 'lib/restspec/endpoints/has_schemas.rb', line 36

def remove_schemas
  schema_roles.clear
end

#schema_for(role_name) ⇒ Object



40
41
42
# File 'lib/restspec/endpoints/has_schemas.rb', line 40

def schema_for(role_name)
  schema_roles[role_name]
end

#schema_rolesObject



12
13
14
# File 'lib/restspec/endpoints/has_schemas.rb', line 12

def schema_roles
  @schema_roles ||= {}
end