Class: FriendlyRoutes::Route
- Inherits:
-
Object
- Object
- FriendlyRoutes::Route
- Defined in:
- lib/friendly_routes/route.rb
Instance Attribute Summary collapse
-
#action ⇒ Object
Returns the value of attribute action.
-
#controller ⇒ Object
Returns the value of attribute controller.
-
#method ⇒ Object
Returns the value of attribute method.
-
#params ⇒ Object
Returns the value of attribute params.
-
#prefix ⇒ Object
Returns the value of attribute prefix.
Instance Method Summary collapse
- #as ⇒ Object
- #boolean(name, params) ⇒ Object
- #collection(name, collection, key_attr) ⇒ Object
- #constraints ⇒ Object
-
#initialize(method, path, controller: nil, action: nil, prefix: 'friendly_routes') ⇒ Route
constructor
A new instance of Route.
- #path ⇒ Object
- #prefixed_param_name(param) ⇒ Object
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
#action ⇒ Object
Returns the value of attribute action.
5 6 7 |
# File 'lib/friendly_routes/route.rb', line 5 def action @action end |
#controller ⇒ Object
Returns the value of attribute controller.
5 6 7 |
# File 'lib/friendly_routes/route.rb', line 5 def controller @controller end |
#method ⇒ Object
Returns the value of attribute method.
5 6 7 |
# File 'lib/friendly_routes/route.rb', line 5 def method @method end |
#params ⇒ Object
Returns the value of attribute params.
5 6 7 |
# File 'lib/friendly_routes/route.rb', line 5 def params @params end |
#prefix ⇒ Object
Returns the value of attribute prefix.
5 6 7 |
# File 'lib/friendly_routes/route.rb', line 5 def prefix @prefix end |
Instance Method Details
#as ⇒ Object
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 |
#constraints ⇒ Object
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 |
#path ⇒ Object
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 |