Class: SimpleParams::NilParams

Inherits:
Params
  • Object
show all
Defined in:
lib/simple_params/nil_params.rb

Constant Summary

Constants included from HasTypedParams

HasTypedParams::TYPES

Instance Attribute Summary

Attributes inherited from Params

#original_params

Instance Method Summary collapse

Methods inherited from Params

api_pie_documentation, model_name, nested_array, nested_arrays, nested_classes, nested_hash, nested_hashes, param

Methods included from Validations

#validate!

Constructor Details

#initialize(params = {}, mocked_object = nil) ⇒ NilParams



3
4
5
6
# File 'lib/simple_params/nil_params.rb', line 3

def initialize(params = {}, mocked_object = nil)
  @mocked_object = mocked_object
  super(params)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *arguments, &block) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/simple_params/nil_params.rb', line 20

def method_missing(method_name, *arguments, &block)
  if @mocked_object.present?
    @mocked_object.send(method_name, *arguments, &block)
  else
    super(method_name, *arguments, &block)
  end
end

Instance Method Details

#errorsObject



16
17
18
# File 'lib/simple_params/nil_params.rb', line 16

def errors
  Errors.new(self)
end

#respond_to?(method_name, include_private = false) ⇒ Boolean



28
29
30
31
32
33
34
# File 'lib/simple_params/nil_params.rb', line 28

def respond_to?(method_name, include_private = false)
  if @mocked_object.present?
    @mocked_object.respond_to?(:method) || super
  else
    super
  end
end

#to_hashObject



12
13
14
# File 'lib/simple_params/nil_params.rb', line 12

def to_hash
  {}
end

#valid?Boolean



8
9
10
# File 'lib/simple_params/nil_params.rb', line 8

def valid?
  true
end