Sha256: 92fcf519ea7efa322ea5610b1c9ab88b9f8509f593dc73dc98a935e6e4f57573

Contents?: true

Size: 569 Bytes

Versions: 9

Compression:

Stored size: 569 Bytes

Contents

module InferredCrumpets
  class RouteChecker
    def initialize(view_context)
      @view_context = view_context
    end

    def linkable?(subject)
      @view_context.url_for(subject) && true
    rescue NoMethodError
      false
    end

    def can_route?(subject, action, params = {})
      @view_context.url_for({
        action:     action,
        controller: subject.class.table_name,
      }.merge(params))
    rescue ActionController::RoutingError # Rails 3
      false
    rescue ActionController::UrlGenerationError # Rails 4+
      false
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
inferred_crumpets-0.7.0 lib/inferred_crumpets/route_checker.rb
inferred_crumpets-0.6.0 lib/inferred_crumpets/route_checker.rb
inferred_crumpets-0.5.0 lib/inferred_crumpets/route_checker.rb
inferred_crumpets-0.4.2 lib/inferred_crumpets/route_checker.rb
inferred_crumpets-0.4.1 lib/inferred_crumpets/route_checker.rb
inferred_crumpets-0.4.0 lib/inferred_crumpets/route_checker.rb
inferred_crumpets-0.3.0 lib/inferred_crumpets/route_checker.rb
inferred_crumpets-0.2.6 lib/inferred_crumpets/route_checker.rb
inferred_crumpets-0.2.5 lib/inferred_crumpets/route_checker.rb