Class: Caliper::RouteWrapper

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
lib/caliper/route_inspector.rb

Instance Method Summary collapse

Instance Method Details

#actionObject



55
56
57
# File 'lib/caliper/route_inspector.rb', line 55

def action
  requirements[:action] || ':action'
end

#constraintsObject



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

def constraints
  requirements.except(:controller, :action)
end

#controllerObject



51
52
53
# File 'lib/caliper/route_inspector.rb', line 51

def controller
  requirements[:controller] || ':controller'
end

#endpointObject



7
8
9
10
11
12
13
# File 'lib/caliper/route_inspector.rb', line 7

def endpoint
  unless rack_app
    "#{controller}##{action}"
  end
  # ignore rack apps for now (don't want to know about redirects)
  #rack_app ? rack_app.inspect : "#{controller}##{action}"
end

#engine?Boolean

Returns:

  • (Boolean)


63
64
65
# File 'lib/caliper/route_inspector.rb', line 63

def engine?
  rack_app && rack_app.respond_to?(:routes)
end

#internal?Boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/caliper/route_inspector.rb', line 59

def internal?
  path =~ %r{/rails/info.*|^#{::Rails.application.config.assets.prefix}}
end

#nameObject



38
39
40
# File 'lib/caliper/route_inspector.rb', line 38

def name
  super.to_s
end

#pathObject



34
35
36
# File 'lib/caliper/route_inspector.rb', line 34

def path
  super.spec.to_s
end

#rack_app(app = self.app) ⇒ Object



19
20
21
22
23
24
25
26
27
28
# File 'lib/caliper/route_inspector.rb', line 19

def rack_app(app = self.app)
  @rack_app ||= begin
    class_name = app.class.name.to_s
    if class_name == "ActionDispatch::Routing::Mapper::Constraints"
      rack_app(app.app)
    elsif ActionDispatch::Routing::Redirect === app || class_name !~ /^ActionDispatch::Routing/
      app
    end
  end
end

#reqsObject



42
43
44
45
46
47
48
49
# File 'lib/caliper/route_inspector.rb', line 42

def reqs
  @reqs ||= begin
    reqs = endpoint
    # commenting out for now until tested and really required
    #reqs += " #{constraints.to_s}" unless constraints.empty?
    reqs
  end
end

#verbObject



30
31
32
# File 'lib/caliper/route_inspector.rb', line 30

def verb
  super.source.gsub(/[$^]/, '')
end