Module: LinkToOnlyValidPath::Helper

Defined in:
lib/link_to_only_valid_path/helper.rb

Instance Method Summary collapse

Instance Method Details



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/link_to_only_valid_path/helper.rb', line 3

def link_to_only_valid_path(*args, &block)
  if block_given?
    options = args.first || {}
    html_options = args.second
    link_to_only_valid_path(capture(&block), options, html_options)
  else
    accepts = ['http', 'https']
    if args[2]
      args[2].stringify_keys!
      if args[2].key?('accept_protocols')
        accepts = args[2]['accept_protocols'].map{ |protocol| protocol.to_s }
        args[2].delete('accept_protocols')
      end
    end
    return link_to_if(valid_path?(args.second, accepts), *args)
  end
end