Class: Restspec::Schema::Types::SchemaIdType
- Defined in:
- lib/restspec/schema/types/schema_id_type.rb
Instance Attribute Summary collapse
-
#schema_name ⇒ Object
Returns the value of attribute schema_name.
Instance Method Summary collapse
- #example_for(attribute) ⇒ Object
-
#initialize(options, options_when_name_is_present = {}) ⇒ SchemaIdType
constructor
A new instance of SchemaIdType.
- #valid?(attribute, value) ⇒ Boolean
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(, = {}) if .is_a?(Symbol) self.schema_name = super() else super() end end |
Instance Attribute Details
#schema_name ⇒ Object
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 .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
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 |