Module: MediaTypes::Dsl::ClassMethods
- Defined in:
- lib/media_types/dsl.rb
Instance Method Summary collapse
- #available_validations ⇒ Object
- #identifier ⇒ Object
- #identifier_format ⇒ Object
- #register ⇒ Object
- #suffix(s) ⇒ Object
- #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
#available_validations ⇒ Object
82 83 84 85 86 87 |
# File 'lib/media_types/dsl.rb', line 82 def available_validations self.media_type_combinations.map do |a| _, view, version, suffix = a view(view).version(version).suffix(suffix) end end |
#identifier ⇒ Object
78 79 80 |
# File 'lib/media_types/dsl.rb', line 78 def identifier to_constructable.to_s end |
#identifier_format ⇒ Object
72 73 74 75 76 |
# File 'lib/media_types/dsl.rb', line 72 def identifier_format self.media_type_name_for = Proc.new do |type:, view:, version:, suffix:| yield(type: type, view: view, version: version, suffix: suffix) end end |
#register ⇒ Object
55 56 57 58 59 60 |
# File 'lib/media_types/dsl.rb', line 55 def register registrations.to_a.map do |registerable| MediaTypes.register(registerable) registerable end end |
#suffix(s) ⇒ Object
68 69 70 |
# File 'lib/media_types/dsl.rb', line 68 def suffix(s) to_constructable.suffix(s) end |
#to_constructable ⇒ Object
27 28 29 30 31 |
# File 'lib/media_types/dsl.rb', line 27 def to_constructable media_type_constructable.dup.tap do |constructable| constructable.__setobj__(self) end end |
#valid?(output, **opts) ⇒ Boolean
33 34 35 |
# File 'lib/media_types/dsl.rb', line 33 def valid?(output, **opts) to_constructable.valid?(output, **opts) end |
#valid_unsafe?(output, media_type = to_constructable, **opts) ⇒ Boolean
37 38 39 |
# File 'lib/media_types/dsl.rb', line 37 def valid_unsafe?(output, media_type = to_constructable, **opts) validations.find(media_type).valid?(output, backtrace: ['.'], **opts) end |
#validatable?(media_type = to_constructable) ⇒ Boolean
49 50 51 52 53 |
# File 'lib/media_types/dsl.rb', line 49 def validatable?(media_type = to_constructable) return false unless validations validations.find(media_type, -> { nil }) end |
#validate!(output, **opts) ⇒ Object
41 42 43 |
# File 'lib/media_types/dsl.rb', line 41 def validate!(output, **opts) to_constructable.validate!(output, **opts) end |
#validate_unsafe!(output, media_type = to_constructable, **opts) ⇒ Object
45 46 47 |
# File 'lib/media_types/dsl.rb', line 45 def validate_unsafe!(output, media_type = to_constructable, **opts) validations.find(media_type).validate(output, backtrace: ['.'], **opts) end |
#version(v) ⇒ Object
65 66 67 |
# File 'lib/media_types/dsl.rb', line 65 def version(v) to_constructable.version(v) end |
#view(v) ⇒ Object
62 63 64 |
# File 'lib/media_types/dsl.rb', line 62 def view(v) to_constructable.view(v) end |