Module: Paramore::PermittedParameterArgument

Defined in:
lib/paramore/permitted_parameter_argument.rb

Class Method Summary collapse

Class Method Details

.flat_parameters(parsed) ⇒ Object



37
38
39
# File 'lib/paramore/permitted_parameter_argument.rb', line 37

def flat_parameters(parsed)
  parsed.select { |arg| arg.is_a?(Symbol) }
end

.merge_hashes(parsed) ⇒ Object



33
34
35
# File 'lib/paramore/permitted_parameter_argument.rb', line 33

def merge_hashes(parsed)
  (flat_parameters(parsed) + nested_parameters(parsed)).compact
end

.nested_parameters(parsed) ⇒ Object



41
42
43
# File 'lib/paramore/permitted_parameter_argument.rb', line 41

def nested_parameters(parsed)
  [parsed.reject { |arg| arg.is_a?(Symbol) }.reduce(:merge)]
end

.parse(field) ⇒ Object



5
6
7
# File 'lib/paramore/permitted_parameter_argument.rb', line 5

def parse(field)
  parse_type(field.type)
end

.parse_type(type) ⇒ Object



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

def parse_type(type)
  merge_hashes(
    case type
    when Array
      parse_type(type.first)
    when Hash
      type.map do |name, field|
        if field.wildly_keyed_hash?
          { name => {} }
        else
          case field.type
          when Array, Hash
            { name => parse_type(field.type) }
          else
            name
          end
        end
      end
    else
      []
    end
  )
end