Class: SimpleParams::NilParams

Inherits:
NestedParams 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

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from NestedParams

array?, define_new_array_class, define_new_hash_class, hash?, #id, #set_accessors, type, with_ids?

Methods inherited from Params

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

Methods included from Validations

#validate!

Constructor Details

#initialize(params = {}) ⇒ NilParams

Returns a new instance of NilParams.



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

def initialize(params = {})      
  self.class.options ||= {}
  @mocked_object = if parent_class
    parent_class.new
  else
    nil
  end
  super(params)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



40
41
42
43
44
45
46
# File 'lib/simple_params/nil_params.rb', line 40

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

Class Method Details

.define_nil_class(parent) ⇒ Object



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

def define_nil_class(parent)
  define_new_class(parent, :nil_params, {}) do
  end
end

.nested_classesObject



9
10
11
12
13
14
15
# File 'lib/simple_params/nil_params.rb', line 9

def nested_classes
  if respond_to?(:parent_class) && parent_class.present?
    parent_class.nested_classes
  else
    {}
  end
end

Instance Method Details

#errorsObject



36
37
38
# File 'lib/simple_params/nil_params.rb', line 36

def errors
  Errors.new(self)
end

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

Returns:

  • (Boolean)


48
49
50
51
52
53
54
# File 'lib/simple_params/nil_params.rb', line 48

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

#to_hashObject



32
33
34
# File 'lib/simple_params/nil_params.rb', line 32

def to_hash
  {}
end

#valid?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/simple_params/nil_params.rb', line 28

def valid?
  true
end