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
110 111 112 113 114 |
# File 'lib/media_types/dsl.rb', line 110 def assert_sane! return if media_type_validations.scheme.asserted_sane? media_type_validations.run_fixture_validations(symbol_keys?) end |
#available_validations ⇒ Object
99 100 101 102 103 104 |
# File 'lib/media_types/dsl.rb', line 99 def available_validations media_type_combinations.map do |a| _, view, version = a view(view).version(version) end end |
#identifier ⇒ Object
95 96 97 |
# File 'lib/media_types/dsl.rb', line 95 def identifier to_constructable.to_s end |
#identifier_format ⇒ Object
89 90 91 92 93 |
# File 'lib/media_types/dsl.rb', line 89 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
74 75 76 77 78 79 |
# File 'lib/media_types/dsl.rb', line 74 def register registrations.to_a.map do |registerable| MediaTypes.register(registerable) registerable end end |
#schema_for(constructable) ⇒ Object
106 107 108 |
# File 'lib/media_types/dsl.rb', line 106 def schema_for(constructable) validations.find(constructable) end |
#string_keys? ⇒ Boolean
43 44 45 |
# File 'lib/media_types/dsl.rb', line 43 def string_keys? !symbol_keys? end |
#symbol_keys? ⇒ Boolean
35 36 37 38 39 40 41 |
# File 'lib/media_types/dsl.rb', line 35 def symbol_keys? if symbol_keys.nil? MediaTypes.get_key_expectation(self) else symbol_keys end end |
#to_constructable ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/media_types/dsl.rb', line 27 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
47 48 49 |
# File 'lib/media_types/dsl.rb', line 47 def valid?(output, **opts) to_constructable.valid?(output, **opts) end |
#valid_unsafe?(output, media_type = to_constructable, **opts) ⇒ Boolean
51 52 53 54 |
# File 'lib/media_types/dsl.rb', line 51 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
66 67 68 69 70 71 72 |
# File 'lib/media_types/dsl.rb', line 66 def validatable?(media_type = to_constructable) return false unless validations resolved = validations.find(media_type, -> { nil }) !resolved.nil? end |
#validate!(output, **opts) ⇒ Object
56 57 58 59 |
# File 'lib/media_types/dsl.rb', line 56 def validate!(output, **opts) assert_sane! to_constructable.validate!(output, **opts) end |
#validate_unsafe!(output, media_type = to_constructable, **opts) ⇒ Object
61 62 63 64 |
# File 'lib/media_types/dsl.rb', line 61 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
85 86 87 |
# File 'lib/media_types/dsl.rb', line 85 def version(v) to_constructable.version(v) end |
#view(v) ⇒ Object
81 82 83 |
# File 'lib/media_types/dsl.rb', line 81 def view(v) to_constructable.view(v) end |