13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/quiver/patcher.rb', line 13
def params(&block)
klass = Class.new do
include Lotus::Validations
def self.param(name, options={}, &block)
attribute(name, options, &block)
nil
end
def self.build_validation_class(&block)
kls = Class.new(self)
kls.class_eval(&block)
kls
end
def initialize(attributes)
@raw_attributes = attributes
super
end
def [](key)
@attributes.get(key)
end
def to_h
super.select do |key, _|
@raw_attributes.to_h.has_key?(key.to_s) || @raw_attributes.to_h.has_key?(key.to_sym)
end
end
end
klass.instance_exec(&block)
instance_variable_set('@params_attributes', klass)
end
|