Module: MediaTypes::Dsl::ClassMethods
- Defined in:
- lib/media_types/dsl.rb
Instance Method Summary collapse
- #assert_sane! ⇒ Object
- #available_validations ⇒ Object
- #identifier ⇒ Object
- #identifier_format ⇒ Object
- #register ⇒ Object
- #schema_for(constructable) ⇒ Object
- #string_keys? ⇒ Boolean
- #symbol_keys? ⇒ Boolean
- #to_constructable ⇒ Object
- #valid?(output, **opts) ⇒ Boolean
- #valid_unsafe?(output, media_type = to_constructable, **opts) ⇒ Boolean
- #validatable?(media_type = to_constructable) ⇒ Boolean
- #validate!(output, **opts) ⇒ Object
- #validate_unsafe!(output, media_type = to_constructable, **opts) ⇒ Object
- #version(v) ⇒ Object
- #view(v) ⇒ Object
Instance Method Details
#assert_sane! ⇒ Object
108 109 110 111 112 |
# File 'lib/media_types/dsl.rb', line 108 def assert_sane! return if media_type_validations.scheme.asserted_sane? media_type_validations.run_fixture_validations(symbol_keys?) end |
#available_validations ⇒ Object
97 98 99 100 101 102 |
# File 'lib/media_types/dsl.rb', line 97 def available_validations media_type_combinations.map do |a| _, view, version = a view(view).version(version) end end |
#identifier ⇒ Object
93 94 95 |
# File 'lib/media_types/dsl.rb', line 93 def identifier to_constructable.to_s end |
#identifier_format ⇒ Object
87 88 89 90 91 |
# File 'lib/media_types/dsl.rb', line 87 def identifier_format self.media_type_name_for = proc do |type:, view:, version:, suffix:| yield(type: type, view: view, version: version, suffix: suffix) end end |
#register ⇒ Object
72 73 74 75 76 77 |
# File 'lib/media_types/dsl.rb', line 72 def register registrations.to_a.map do |registerable| MediaTypes.register(registerable) registerable end end |
#schema_for(constructable) ⇒ Object
104 105 106 |
# File 'lib/media_types/dsl.rb', line 104 def schema_for(constructable) validations.find(constructable) end |
#string_keys? ⇒ Boolean
41 42 43 |
# File 'lib/media_types/dsl.rb', line 41 def string_keys? !symbol_keys? end |
#symbol_keys? ⇒ Boolean
33 34 35 36 37 38 39 |
# File 'lib/media_types/dsl.rb', line 33 def symbol_keys? if symbol_keys.nil? MediaTypes.get_key_expectation(self) else symbol_keys end end |
#to_constructable ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/media_types/dsl.rb', line 25 def to_constructable raise UninitializedConstructable if media_type_constructable.nil? media_type_constructable.dup.tap do |constructable| constructable.__setobj__(self) end end |
#valid?(output, **opts) ⇒ Boolean
45 46 47 |
# File 'lib/media_types/dsl.rb', line 45 def valid?(output, **opts) to_constructable.valid?(output, **opts) end |
#valid_unsafe?(output, media_type = to_constructable, **opts) ⇒ Boolean
49 50 51 52 |
# File 'lib/media_types/dsl.rb', line 49 def valid_unsafe?(output, media_type = to_constructable, **opts) opts[:expected_key_type] = string_keys? ? String : Symbol validations.find(media_type).valid?(output, backtrace: ['.'], **opts) end |
#validatable?(media_type = to_constructable) ⇒ Boolean
64 65 66 67 68 69 70 |
# File 'lib/media_types/dsl.rb', line 64 def validatable?(media_type = to_constructable) return false unless validations resolved = validations.find(media_type, -> { nil }) !resolved.nil? end |
#validate!(output, **opts) ⇒ Object
54 55 56 57 |
# File 'lib/media_types/dsl.rb', line 54 def validate!(output, **opts) assert_sane! to_constructable.validate!(output, **opts) end |
#validate_unsafe!(output, media_type = to_constructable, **opts) ⇒ Object
59 60 61 62 |
# File 'lib/media_types/dsl.rb', line 59 def validate_unsafe!(output, media_type = to_constructable, **opts) opts[:expected_key_type] = string_keys? ? String : Symbol validations.find(media_type).validate(output, backtrace: ['.'], **opts) end |
#version(v) ⇒ Object
83 84 85 |
# File 'lib/media_types/dsl.rb', line 83 def version(v) to_constructable.version(v) end |
#view(v) ⇒ Object
79 80 81 |
# File 'lib/media_types/dsl.rb', line 79 def view(v) to_constructable.view(v) end |