Class: BinData::SanitizedParameters

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/bindata/sanitize.rb

Overview

A BinData object accepts arbitrary parameters. This class ensures that the parameters have been sanitized, and categorizes them according to whether they are BinData::Base.accepted_parameters or are extra.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(klass, params, *args) ⇒ SanitizedParameters

Sanitize the given parameters.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/bindata/sanitize.rb', line 11

def initialize(klass, params, *args)
  params ||= {}
  @hash = klass.sanitize_parameters(params, *args)
  @accepted_parameters = {}
  @extra_parameters = {}

  # partition parameters into known and extra parameters
  @hash.each do |k,v|
    k = k.to_sym
    if v.nil?
      raise ArgumentError, "parameter :#{k} has nil value in #{klass}"
    end

    if klass.accepted_parameters.include?(k)
      @accepted_parameters[k] = v
    else
      @extra_parameters[k] = v
    end
  end
end

Instance Attribute Details

#accepted_parametersObject (readonly)

Returns the value of attribute accepted_parameters.



32
33
34
# File 'lib/bindata/sanitize.rb', line 32

def accepted_parameters
  @accepted_parameters
end

#extra_parametersObject (readonly)

Returns the value of attribute extra_parameters.



32
33
34
# File 'lib/bindata/sanitize.rb', line 32

def extra_parameters
  @extra_parameters
end