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



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

def initialize(params)
  @params = params

  @database = {
    dashboard: {
      show: [],
    },
    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



52
53
54
55
56
57
58
59
60
# File 'lib/test_server/permitted_params.rb', line 52

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



42
43
44
45
46
47
48
49
50
# File 'lib/test_server/permitted_params.rb', line 42

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