Class: MediaTypes::Validations
- Inherits:
-
Object
- Object
- MediaTypes::Validations
- Defined in:
- lib/media_types/validations.rb
Overview
Takes care of registering validations for a media type. It allows for nested schemes and registers each one so it can be looked up at a later time.
Instance Method Summary collapse
-
#find(media_type, default = -> { Scheme::NotStrict.new }) ⇒ Scheme
Looks up the validations for Constructable.
-
#initialize(media_type, registry = {}, scheme = Scheme.new, &block) ⇒ Validations
constructor
Creates a new stack of validations.
- #method_missing(method_name, *arguments, &block) ⇒ Object
- #respond_to_missing?(method_name, include_private = false) ⇒ Boolean
Constructor Details
#initialize(media_type, registry = {}, scheme = Scheme.new, &block) ⇒ Validations
Creates a new stack of validations
26 27 28 29 30 31 32 |
# File 'lib/media_types/validations.rb', line 26 def initialize(media_type, registry = {}, scheme = Scheme.new, &block) self.media_type = media_type self.registry = registry.merge!(media_type.to_s => scheme) self.scheme = scheme instance_exec(&block) if block_given? end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *arguments, &block) ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/media_types/validations.rb', line 45 def method_missing(method_name, *arguments, &block) if scheme.respond_to?(method_name) return scheme.send(method_name, *arguments, &block) end super end |
Instance Method Details
#find(media_type, default = -> { Scheme::NotStrict.new }) ⇒ Scheme
Looks up the validations for Constructable
41 42 43 |
# File 'lib/media_types/validations.rb', line 41 def find(media_type, default = -> { Scheme::NotStrict.new }) registry.fetch(String(media_type)) { default.call } end |
#respond_to_missing?(method_name, include_private = false) ⇒ Boolean
53 54 55 |
# File 'lib/media_types/validations.rb', line 53 def respond_to_missing?(method_name, include_private = false) scheme.respond_to?(method_name) || super end |