Module: GoToParam

Defined in:
lib/go_to_param.rb,
lib/go_to_param/version.rb

Constant Summary collapse

VERSION =
"1.1.3"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.allow_redirect_prefix(prefix) ⇒ Object



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

def self.allow_redirect_prefix(prefix)
  allowed_redirect_prefixes << prefix
end

.allowed_redirect_prefixesObject



9
10
11
12
# File 'lib/go_to_param.rb', line 9

def self.allowed_redirect_prefixes
  reset_allowed_redirect_prefixes unless @allowed_redirect_prefixes
  @allowed_redirect_prefixes
end

.included(klass) ⇒ Object



19
20
21
22
23
# File 'lib/go_to_param.rb', line 19

def self.included(klass)
  klass.helper_method :hidden_go_to_tag, :hidden_go_to_here_tag,
    :go_to_params, :go_to_here_params,
    :go_to_path, :go_to_path_or
end

.reset_allowed_redirect_prefixesObject

Mostly for tests…



15
16
17
# File 'lib/go_to_param.rb', line 15

def self.reset_allowed_redirect_prefixes
  @allowed_redirect_prefixes = [ "/" ]
end

Instance Method Details

#go_to_here_params(additional_query_params = {}) ⇒ Object



37
38
39
40
41
42
43
44
45
# File 'lib/go_to_param.rb', line 37

def go_to_here_params(additional_query_params = {})
  path = go_to_here_path(**additional_query_params)

  if path
    { go_to: path }
  else
    {}
  end
end

#go_to_params(other_params = {}) ⇒ Object



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

def go_to_params(other_params = {})
  { go_to: go_to_path }.merge(other_params)
end

#go_to_pathObject



47
48
49
50
51
52
53
54
55
56
# File 'lib/go_to_param.rb', line 47

def go_to_path
  return nil if go_to_param_value.nil?

  # Avoid phishing redirects.
  if matches_allowed_redirect_prefixes?
    go_to_param_value
  else
    nil
  end
end

#go_to_path_or(default) ⇒ Object



58
59
60
# File 'lib/go_to_param.rb', line 58

def go_to_path_or(default)
  go_to_path || default
end

#hidden_go_to_here_tag(additional_query_params = {}) ⇒ Object



29
30
31
# File 'lib/go_to_param.rb', line 29

def hidden_go_to_here_tag(additional_query_params = {})
  view_context.hidden_field_tag :go_to, go_to_here_params(additional_query_params)[:go_to]
end

#hidden_go_to_tagObject



25
26
27
# File 'lib/go_to_param.rb', line 25

def hidden_go_to_tag
  view_context.hidden_field_tag :go_to, go_to_path
end