Module: PostJson::ArgumentMethods

Extended by:
ActiveSupport::Concern
Included in:
DynamicIndex, FinderMethods, QueryMethods
Defined in:
lib/post_json/concerns/argument_methods.rb

Instance Method Summary collapse

Instance Method Details

#assert_valid_indifferent_keys(options, *valid_keys) ⇒ Object


29
30
31
# File 'lib/post_json/concerns/argument_methods.rb', line 29

def assert_valid_indifferent_keys(options, *valid_keys)
  options.stringify_keys.assert_valid_keys(flatten_arguments(*valid_keys))
end

#flatten_arguments(*arguments) ⇒ Object


25
26
27
# File 'lib/post_json/concerns/argument_methods.rb', line 25

def flatten_arguments(*arguments)
  join_arguments(*arguments).split(',')
end

#join_arguments(*arguments) ⇒ Object


5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/post_json/concerns/argument_methods.rb', line 5

def join_arguments(*arguments)
  arguments = arguments[0] if arguments.length == 1 && arguments[0].is_a?(Array)
  arguments = arguments[0].split(',') if arguments.length == 1 && arguments[0].is_a?(String)

  arguments = arguments.map do |arg|
    case arg
    when nil
      nil
    when String
      arg.strip.gsub(/\s+/, ' ')
    when Symbol
      arg.to_s
    else
      arg
    end
  end

  arguments.join(',')
end