Class: TestServer::PermittedParams

Inherits:
Object
  • Object
show all
Defined in:
lib/test_server/permitted_params.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params) ⇒ PermittedParams

Returns a new instance of PermittedParams.



12
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
# File 'lib/test_server/permitted_params.rb', line 12

def initialize(params)
  @params = params

  @database = {
    dashboard: {
      show: [],
    },
    reflector: {
      client_ip_address: [],
      index: [],
    },
    static: {
      index: [],
    },
    streaming: {
      plain:  [:encodable, :streamable, :cachable, :countable],
      random: [:encodable, :streamable, :cachable, :countable],
      eicar:  [:encodable, :streamable, :cachable],
      index: [],
    },
    string: {
      plain:  [:encodable, :streamable, :cachable, :countable],
      random: [:encodable, :streamable, :cachable, :countable],
      sleep:  [:encodable, :streamable, :cachable, :countable],
      eicar:  [:encodable, :streamable, :cachable],
      index: [],
    },
    generator: {
      xhr: [:generatable, :repeatable],
      index: [],
    },
  }
end

Instance Attribute Details

#paramsObject (readonly)

Returns the value of attribute params.



10
11
12
# File 'lib/test_server/permitted_params.rb', line 10

def params
  @params
end

Instance Method Details

#known_params_for_controller(name, action) ⇒ Object



56
57
58
59
60
61
62
63
64
# File 'lib/test_server/permitted_params.rb', line 56

def known_params_for_controller(name, action)
  name   = name.to_sym
  action = action.to_sym

  raise Exceptions::ControllerNotDefinedInParameterList, JSON.dump(controller: name) unless database.key? name
  raise Exceptions::ActionNotDefinedInParameterList, JSON.dump(action: action)       unless database[name].key? action
  
  params_for(database[name][action]).to_a.sort
end

#params_for_controller(name, action, defaults) ⇒ Object



46
47
48
49
50
51
52
53
54
# File 'lib/test_server/permitted_params.rb', line 46

def params_for_controller(name, action, defaults)
  name   = name.to_sym
  action = action.to_sym

  raise Exceptions::ControllerNotDefinedInParameterList unless database.key? name
  raise Exceptions::ActionNotDefinedInParameterList     unless database[name].key? action

  generate_params(defaults, params_for(database[name][action]))
end