Module: Headmin::RequestHelper

Included in:
AdminHelper
Defined in:
app/helpers/headmin/request_helper.rb

Instance Method Summary collapse

Instance Method Details

#add_default_param_key(key) ⇒ Object



16
17
18
19
20
# File 'app/helpers/headmin/request_helper.rb', line 16

def add_default_param_key(key)
  keys = default_param_keys || []
  keys.push(key)
  @default_param_keys = keys
end

#current_url?(url) ⇒ Boolean

Returns:

  • (Boolean)


3
4
5
6
7
8
9
10
# File 'app/helpers/headmin/request_helper.rb', line 3

def current_url?(url)
  uri = URI(url)
  path = uri.path
  query_string = uri.query || ""
  matches_path = request.path.include?(path)
  matches_query = request.query_string.include?(query_string)
  matches_path && matches_query
end

#default_param_keysObject



22
23
24
# File 'app/helpers/headmin/request_helper.rb', line 22

def default_param_keys
  @default_param_keys ||= [:page, :start, :length, :per_page]
end

#default_paramsObject



12
13
14
# File 'app/helpers/headmin/request_helper.rb', line 12

def default_params
  params.select { |key, value| is_default_param?(key) }
end

#is_default_param?(key) ⇒ Boolean

Returns:

  • (Boolean)


26
27
28
# File 'app/helpers/headmin/request_helper.rb', line 26

def is_default_param?(key)
  default_param_keys.include?(key.to_sym) || is_sort_param_key?(key)
end

#is_sort_param_key?(key) ⇒ Boolean

Returns:

  • (Boolean)


30
31
32
# File 'app/helpers/headmin/request_helper.rb', line 30

def is_sort_param_key?(key)
  key.to_s.include?("sort_")
end