Class: IdentityMind::Params

Inherits:
OpenStruct
  • Object
show all
Defined in:
lib/identity_mind/params.rb

Constant Summary collapse

LENGTH_LIMITS =
YAML.load_file(
  File.join(__dir__, 'params_length_limits.yml')
).freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash = nil) ⇒ Params

Returns a new instance of Params.



14
15
16
17
18
19
20
21
# File 'lib/identity_mind/params.rb', line 14

def initialize(hash = nil)
  @table = {}
  return unless hash

  hash.each_pair do |k, v|
    @table[k.to_sym] = parse_param(v, k)
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(mid, *args) ⇒ Object



31
32
33
34
# File 'lib/identity_mind/params.rb', line 31

def method_missing(mid, *args)
  args[0] = parse_param(args[0], mid) if args[0]
  super
end

Class Method Details

.[](hash) ⇒ Object



8
9
10
11
12
# File 'lib/identity_mind/params.rb', line 8

def self.[](hash)
  return hash if hash.is_a?(self)

  new(hash)
end

Instance Method Details

#[]=(name, value) ⇒ Object



23
24
25
# File 'lib/identity_mind/params.rb', line 23

def []=(name, value)
  super(name, parse_param(value, name))
end

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

Returns:

  • (Boolean)


36
37
38
# File 'lib/identity_mind/params.rb', line 36

def respond_to_missing?(method_name, include_private = false)
  super
end

#to_json(opts = {}) ⇒ Object



27
28
29
# File 'lib/identity_mind/params.rb', line 27

def to_json(opts = {})
  @table.to_json(opts)
end