Module: RSchema::Rails::Controller::ClassMethods

Defined in:
lib/rschema/rails.rb

Overview

Class methods added to ActionController classes

Constant Summary collapse

DEFAULT_OPTIONS =
{
  coercion_wrapper: RSchema::CoercionWrapper::RACK_PARAMS
}.freeze

Instance Method Summary collapse

Instance Method Details

#__rschema_get_optionsObject


60
61
62
63
64
65
66
67
68
# File 'lib/rschema/rails.rb', line 60

def __rschema_get_options
  self.ancestors.reverse.reduce(DEFAULT_OPTIONS) do |options, klass|
    if klass.instance_variable_defined?(:@__rschema_options)
      options.merge(klass.instance_variable_get(:@__rschema_options))
    else
      options
    end
  end
end

#param_schema(&schema_block) ⇒ Object


45
46
47
48
49
# File 'lib/rschema/rails.rb', line 45

def param_schema(&schema_block)
  schema = RSchema.define_hash(&schema_block)
  coercer = rschema_options.fetch(:coercion_wrapper)
  coercer ? coercer.wrap(schema) : schema
end

#rschema_options(options = nil) ⇒ Object


51
52
53
54
55
56
57
58
# File 'lib/rschema/rails.rb', line 51

def rschema_options(options = nil)
  if options.nil?
    __rschema_get_options
  else
    @__rschema_options ||= {}
    @__rschema_options.merge!(options)
  end
end