Class: JsRoutes::Route

Inherits:
Object
  • Object
show all
Defined in:
lib/js_routes/route.rb

Overview

:nodoc:

Constant Summary collapse

FILTERED_DEFAULT_PARTS =
[:controller, :action]
URL_OPTIONS =
[:protocol, :domain, :host, :port, :subdomain]
NODE_TYPES =
{
  GROUP: 1,
  CAT: 2,
  SYMBOL: 3,
  OR: 4,
  STAR: 5,
  LITERAL: 6,
  SLASH: 7,
  DOT: 8
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(configuration, route, parent_route = nil) ⇒ Route

Returns a new instance of Route.



18
19
20
21
22
# File 'lib/js_routes/route.rb', line 18

def initialize(configuration, route, parent_route = nil)
  @configuration = configuration
  @route = route
  @parent_route = parent_route
end

Instance Attribute Details

#configurationObject (readonly)

Returns the value of attribute configuration.



16
17
18
# File 'lib/js_routes/route.rb', line 16

def configuration
  @configuration
end

#parent_routeObject (readonly)

Returns the value of attribute parent_route.



16
17
18
# File 'lib/js_routes/route.rb', line 16

def parent_route
  @parent_route
end

#routeObject (readonly)

Returns the value of attribute route.



16
17
18
# File 'lib/js_routes/route.rb', line 16

def route
  @route
end

Instance Method Details

#body(absolute) ⇒ Object



35
36
37
38
# File 'lib/js_routes/route.rb', line 35

def body(absolute)
  @configuration.dts? ?
    definition_body : "__jsr.r(#{arguments(absolute).map{|a| json(a)}.join(', ')})"
end

#definition_bodyObject



40
41
42
43
44
# File 'lib/js_routes/route.rb', line 40

def definition_body
  args = required_parts.map{|p| "#{apply_case(p)}: RequiredRouteParameter"}
  args << "options?: #{optional_parts_type} & RouteOptions"
  "((\n#{args.join(",\n").indent(2)}\n) => string) & RouteHelperExtras"
end

#helper_typesObject



30
31
32
33
# File 'lib/js_routes/route.rb', line 30

def helper_types
  return [] unless match_configuration?
  @configuration[:url_links] ? [true, false] : [false]
end

#helpersObject



24
25
26
27
28
# File 'lib/js_routes/route.rb', line 24

def helpers
  helper_types.map do |absolute|
    [ documentation, helper_name(absolute), body(absolute) ]
  end
end

#optional_parts_typeObject



46
47
48
49
# File 'lib/js_routes/route.rb', line 46

def optional_parts_type
  @optional_parts_type ||=
    "{" + optional_parts.map {|p| "#{p}?: OptionalRouteParameter"}.join(', ') + "}"
end