Module: Contrast::Api::Decorators::RouteCoverage::ClassMethods

Defined in:
lib/contrast/api/decorators/route_coverage.rb

Overview

Class methods for RouteCoverage

Instance Method Summary collapse

Instance Method Details

#from_action_dispatch_journey(journey_obj) ⇒ Contrast::Api::Dtm::RouteCoverage

Convert ActionDispatch::Journey::Route to Contrast::Api::Dtm::RouteCoverage

Parameters:

  • journey_obj (ActionDispatch::Journey::Route)

    a rails route

Returns:



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/contrast/api/decorators/route_coverage.rb', line 31

def from_action_dispatch_journey journey_obj
  msg = new
  msg.route = "#{ journey_obj.defaults[:controller] }##{ journey_obj.defaults[:action] }"

  verb = source_or_string(journey_obj.verb)
  msg.verb = Contrast::Utils::StringUtils.force_utf8(verb)

  url = source_or_string(journey_obj.path.spec)
  msg.url = Contrast::Utils::StringUtils.force_utf8(url)
  msg
end

#from_sinatra_route(clazz, method, pattern) ⇒ Object



43
44
45
46
47
48
49
50
51
# File 'lib/contrast/api/decorators/route_coverage.rb', line 43

def from_sinatra_route clazz, method, pattern
  safe_pattern = source_or_string(pattern)

  msg = new
  msg.route = "#{ clazz }##{ method } #{ safe_pattern }"
  msg.verb = Contrast::Utils::StringUtils.force_utf8(method)
  msg.url = Contrast::Utils::StringUtils.force_utf8(safe_pattern)
  msg
end

#source_or_string(obj) ⇒ Object



18
19
20
21
22
23
24
25
26
# File 'lib/contrast/api/decorators/route_coverage.rb', line 18

def source_or_string obj
  if obj.cs__is_a?(Regexp)
    obj.source
  elsif obj.cs__respond_to?(:safe_string)
    obj.safe_string
  else
    obj.to_s
  end
end