Class: OpenStax::Connect::RouteHelper

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/openstax/connect/route_helper.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRouteHelper

Returns a new instance of RouteHelper.



24
25
26
27
# File 'lib/openstax/connect/route_helper.rb', line 24

def initialize
  self.paths = {}
  self.stubbed_paths = {}
end

Instance Attribute Details

#pathsObject

Returns the value of attribute paths.



29
30
31
# File 'lib/openstax/connect/route_helper.rb', line 29

def paths
  @paths
end

#stubbed_pathsObject

Returns the value of attribute stubbed_paths.



30
31
32
# File 'lib/openstax/connect/route_helper.rb', line 30

def stubbed_paths
  @stubbed_paths
end

Class Method Details

.get_path(canonical_name) ⇒ Object



18
19
20
21
22
# File 'lib/openstax/connect/route_helper.rb', line 18

def self.get_path(canonical_name)
  OpenStax::Connect.configuration.enable_stubbing? ?
    instance.stubbed_paths[canonical_name] :
    instance.paths[canonical_name]
end

.register_path(canonical_name, path, &block) ⇒ Object

Registers a path against a canonical name. An optional block can be provided to give the stubbed path



11
12
13
14
15
16
# File 'lib/openstax/connect/route_helper.rb', line 11

def self.register_path(canonical_name, path, &block)
  instance.paths[canonical_name] = path
  if block.present? && OpenStax::Connect.configuration.enable_stubbing?
    instance.stubbed_paths[canonical_name] = block.call
  end
end