Module: Quiver::Patcher::ClassMethods

Defined in:
lib/quiver/patcher.rb

Instance Method Summary collapse

Instance Method Details

#get_params_attributes_klassObject



48
49
50
# File 'lib/quiver/patcher.rb', line 48

def get_params_attributes_klass
  instance_variable_get('@params_attributes')
end

#params(&block) ⇒ Object



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

#values(&block) ⇒ Object



9
10
11
# File 'lib/quiver/patcher.rb', line 9

def values(&block)
  warn '`values` is no longer supported.'
end