Sha256: c84b68a46570a72f1c0d48d0603ff061dd4162131e0dcfc8d7a62b659dd34c85

Contents?: true

Size: 980 Bytes

Versions: 2

Compression:

Stored size: 980 Bytes

Contents

module JumpBack
  
  module Helpers
    
    def link_back(name='back', path=root_path, options={})
      args = HelpersArguments.parse(name, path, options, root_path)
      link_to args[:name], PathFinder.new(request, args[:path], args[:jump_back_options]).path, args[:redirect_options]
    end
  end
  
  module HelpersArguments
    
    def self.parse(name, path, options, root_path)
      if first_arg_is_path?(name, path, root_path)
        options = path if path.is_a? Hash
        path = name
        name = 'back'
      end
      if name.is_a? Hash
        options = name
        name = 'back'
      end
      options = OptionsParser.new(default: root_path, path: path, options: options)
      { name: name, path: options.path, jump_back_options: options.jump_back_options, redirect_options: options.redirect_options }
    end
    
    def self.first_arg_is_path?(name, path, root_path)
      Urls.is_url?(name) && (path == root_path || path.is_a?(Hash))
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
jump_back-0.3.2 lib/jump_back/link_back.rb
jump_back-0.3.1 lib/jump_back/link_back.rb