Class: Restspec::Schema::Types::SchemaIdType

Inherits:
BasicType
  • Object
show all
Defined in:
lib/restspec/schema/types/schema_id_type.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from BasicType

#of, #to_s, #totally_valid?, #|

Constructor Details

#initialize(options, options_when_name_is_present = {}) ⇒ SchemaIdType

Returns a new instance of SchemaIdType.



5
6
7
8
9
10
11
12
# File 'lib/restspec/schema/types/schema_id_type.rb', line 5

def initialize(options, options_when_name_is_present = {})
  if options.is_a?(Symbol)
    self.schema_name = options
    super(options_when_name_is_present)
  else
    super(options)
  end
end

Instance Attribute Details

#schema_nameObject

Returns the value of attribute schema_name.



3
4
5
# File 'lib/restspec/schema/types/schema_id_type.rb', line 3

def schema_name
  @schema_name
end

Instance Method Details

#example_for(attribute) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/restspec/schema/types/schema_id_type.rb', line 14

def example_for(attribute)
  return sample_item.id if sample_item.present?

  if create_response.code == 201 && create_response.body.try(:id)
    create_response.body.id
  else
    example_options.fetch(:hardcoded_fallback) {
      raise "We couldn't fetch any information for this example"
    }
  end
rescue URI::InvalidURIError, Errno::ECONNREFUSED => e
  puts "WARNING: Error calling api #{e}. Falling back to use a number."
  Faker::Number.digit
end

#valid?(attribute, value) ⇒ Boolean

Returns:

  • (Boolean)


29
30
31
32
# File 'lib/restspec/schema/types/schema_id_type.rb', line 29

def valid?(attribute, value)
  return true unless perform_validation?
  item_ids.any? { |item| item.id == value }
end