module ParamsReady::Marshaller::DefinitionModule
Attributes
marshallers[R]
Public Class Methods
[](collection)
click to toggle source
# File lib/params_ready/marshaller/definition_module.rb, line 4 def self.[](collection) mod = Module.new mod.include self mod.define_method :class_marshallers do collection end mod end
new(*args, marshaller: nil, **options)
click to toggle source
Calls superclass method
# File lib/params_ready/marshaller/definition_module.rb, line 15 def initialize(*args, marshaller: nil, **options) @marshallers = class_marshallers.instance_collection set_marshaller(**marshaller) unless marshaller.nil? super *args, **options end
Public Instance Methods
finish()
click to toggle source
Calls superclass method
# File lib/params_ready/marshaller/definition_module.rb, line 48 def finish unless @marshallers.default? if class_marshallers.default? @marshallers.default = class_marshallers.default end end super end
freeze()
click to toggle source
Calls superclass method
# File lib/params_ready/marshaller/definition_module.rb, line 57 def freeze @marshallers.freeze super end
marshal(parameter, intent, **opts)
click to toggle source
# File lib/params_ready/marshaller/definition_module.rb, line 36 def marshal(parameter, intent, **opts) if intent.marshal?(name_for_formatter) @marshallers.marshal(parameter, intent, **opts) else @marshallers.marshal_canonical(parameter, intent, **opts) end end
set_marshaller(to: nil, using: nil, **opts)
click to toggle source
# File lib/params_ready/marshaller/definition_module.rb, line 22 def set_marshaller(to: nil, using: nil, **opts) if using.is_a? Symbol raise ParamsReadyError, "Expected ':to' argument to be nil, got #{to.class.name}" unless to.nil? default_class, instance = class_marshallers.build_instance(using, **opts) @marshallers.add_instance(default_class, instance) @marshallers.default!(default_class) elsif using.nil? @marshallers.default!(to) else @marshallers.add_instance(to, using) @marshallers.default!(to) end end
try_canonicalize(input, context, validator = nil, **opts)
click to toggle source
# File lib/params_ready/marshaller/definition_module.rb, line 44 def try_canonicalize(input, context, validator = nil, **opts) @marshallers.canonicalize(self, input, context, validator, **opts) end