class InferredCrumpets::RouteChecker

Public Class Methods

new(view_context) click to toggle source
# File lib/inferred_crumpets/route_checker.rb, line 3
def initialize(view_context)
  @view_context = view_context
end

Public Instance Methods

can_route?(subject, action, params = {}) click to toggle source
# File lib/inferred_crumpets/route_checker.rb, line 13
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
linkable?(subject) click to toggle source
# File lib/inferred_crumpets/route_checker.rb, line 7
def linkable?(subject)
  @view_context.url_for(subject) && true
rescue NoMethodError
  false
end