Class: FriendlyRoutes::Route

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(method, path, controller: nil, action: nil, prefix: 'friendly_routes') ⇒ Route

Returns a new instance of Route.



7
8
9
10
11
12
13
14
# File 'lib/friendly_routes/route.rb', line 7

def initialize(method, path, controller: nil, action: nil, prefix: 'friendly_routes')
  @method = method
  @original_path = path
  @controller = controller
  @action = action
  @params = []
  @prefix = prefix
end

Instance Attribute Details

#actionObject

Returns the value of attribute action.



5
6
7
# File 'lib/friendly_routes/route.rb', line 5

def action
  @action
end

#controllerObject

Returns the value of attribute controller.



5
6
7
# File 'lib/friendly_routes/route.rb', line 5

def controller
  @controller
end

#methodObject

Returns the value of attribute method.



5
6
7
# File 'lib/friendly_routes/route.rb', line 5

def method
  @method
end

#paramsObject

Returns the value of attribute params.



5
6
7
# File 'lib/friendly_routes/route.rb', line 5

def params
  @params
end

#prefixObject

Returns the value of attribute prefix.



5
6
7
# File 'lib/friendly_routes/route.rb', line 5

def prefix
  @prefix
end

Instance Method Details

#asObject



32
33
34
# File 'lib/friendly_routes/route.rb', line 32

def as
  "#{@prefix}_#{@controller}_#{@action}"
end

#boolean(name, params) ⇒ Object



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

def boolean(name, params)
  @params.push(Params::Boolean.new(name, params))
end

#collection(name, collection, key_attr) ⇒ Object



20
21
22
# File 'lib/friendly_routes/route.rb', line 20

def collection(name, collection, key_attr)
  @params.push(Params::Collection.new(name, collection, key_attr))
end

#constraintsObject



36
37
38
39
40
# File 'lib/friendly_routes/route.rb', line 36

def constraints
  @params.map do |param|
    [prefixed_param_name(param).to_sym, param.constraints]
  end.to_h
end

#pathObject



24
25
26
# File 'lib/friendly_routes/route.rb', line 24

def path
  @original_path + mapped_params
end

#prefixed_param_name(param) ⇒ Object



28
29
30
# File 'lib/friendly_routes/route.rb', line 28

def prefixed_param_name(param)
  "#{@prefix}_#{param.name}"
end