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
45
46
47
48
49
50
51
# File 'lib/test_server/permitted_params.rb', line 12

def initialize(params)
  @params = params

  @database = {
    # controller name
    dashboard: {
      # action: role1, role2, ...
      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: [],
    },
    file_uploader: {
      upload: [],
      result: [:uploadable],
      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



63
64
65
66
67
68
69
70
71
# File 'lib/test_server/permitted_params.rb', line 63

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



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

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

  raise Exceptions::ControllerNotDefinedInParameterList, JSON.dump(name: name) unless database.key? name
  raise Exceptions::ActionNotDefinedInParameterList, JSON.dump(action: action) unless database[name].key? action

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