Module: ApiSim::ViewHelpers

Defined in:
lib/api_sim/view_helpers.rb

Instance Method Summary collapse

Instance Method Details

#configObject



15
16
17
# File 'lib/api_sim/view_helpers.rb', line 15

def config
  @config
end

#custom_matcher?(endpoint) ⇒ Boolean

Returns:

  • (Boolean)


7
8
9
# File 'lib/api_sim/view_helpers.rb', line 7

def custom_matcher?(endpoint)
  endpoint.custom_matcher? ? '(Custom matcher)' : ''
end

#endpoint_match(endpoint) ⇒ Object



41
42
43
44
45
46
47
# File 'lib/api_sim/view_helpers.rb', line 41

def endpoint_match (endpoint)
  if endpoint.match_on_body? then
    "/#{endpoint.matcher.source}/"
  else
    ''
  end
end

#endpoint_query_string(endpoint) ⇒ Object



11
12
13
# File 'lib/api_sim/view_helpers.rb', line 11

def endpoint_query_string(endpoint)
  "?#{endpoint.query}" if endpoint.query != ''
end

#endpointsObject



3
4
5
# File 'lib/api_sim/view_helpers.rb', line 3

def endpoints
  self.class.endpoints.reject(&:overridden?).sort_by { |endpoint| [endpoint.http_method, endpoint.route].join(' ') }
end

#h(text) ⇒ Object



28
29
30
# File 'lib/api_sim/view_helpers.rb', line 28

def h(text)
  Rack::Utils.escape_html(text)
end


32
33
34
35
36
37
38
39
# File 'lib/api_sim/view_helpers.rb', line 32

def link_to_read_requests(endpoint)
  match = endpoint.match_on_body? ? endpoint.matcher.source : ''
  <<-HTML
    <a href="#{ui_root}/requests/#{endpoint.http_method}#{endpoint.route}?match=#{match}">
      #{endpoint.requests.count}
    </a>
  HTML
end


19
20
21
22
23
24
25
26
# File 'lib/api_sim/view_helpers.rb', line 19

def link_to_response_edit(endpoint)
  match = endpoint.match_on_body? ? endpoint.matcher.source : ''
  <<-HTML
  <a href="#{ui_root}/response/#{endpoint.http_method}#{endpoint.route}?match=#{match}">
    #{endpoint.route}
  </a>
  HTML
end

#ui_rootObject



49
50
51
# File 'lib/api_sim/view_helpers.rb', line 49

def ui_root
  self.class.ui_root
end