Class: RailsBestPractices::Core::Route
- Inherits:
-
Object
- Object
- RailsBestPractices::Core::Route
- Defined in:
- lib/rails_best_practices/core/routes.rb
Instance Attribute Summary collapse
-
#action_name ⇒ Object
readonly
Returns the value of attribute action_name.
-
#controller_name ⇒ Object
readonly
Returns the value of attribute controller_name.
-
#namespaces ⇒ Object
readonly
Returns the value of attribute namespaces.
Instance Method Summary collapse
- #controller_name_with_namespaces ⇒ Object
-
#initialize(namespaces, controller_name, action_name) ⇒ Route
constructor
A new instance of Route.
- #to_s ⇒ Object
Constructor Details
#initialize(namespaces, controller_name, action_name) ⇒ Route
Returns a new instance of Route.
20 21 22 23 24 25 26 27 28 |
# File 'lib/rails_best_practices/core/routes.rb', line 20 def initialize(namespaces, controller_name, action_name) @namespaces = namespaces if controller_name entities = controller_name.split('/') @namespaces += entities[0..-2] if entities.size > 1 @controller_name = entities.last end @action_name = action_name end |
Instance Attribute Details
#action_name ⇒ Object (readonly)
Returns the value of attribute action_name.
18 19 20 |
# File 'lib/rails_best_practices/core/routes.rb', line 18 def action_name @action_name end |
#controller_name ⇒ Object (readonly)
Returns the value of attribute controller_name.
18 19 20 |
# File 'lib/rails_best_practices/core/routes.rb', line 18 def controller_name @controller_name end |
#namespaces ⇒ Object (readonly)
Returns the value of attribute namespaces.
18 19 20 |
# File 'lib/rails_best_practices/core/routes.rb', line 18 def namespaces @namespaces end |
Instance Method Details
#controller_name_with_namespaces ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/rails_best_practices/core/routes.rb', line 30 def controller_name_with_namespaces if controller_name namespaces.map { |namespace| "#{namespace.camelize}::" }.join("") + "#{controller_name.camelize}Controller" else namespaces.map { |namespace| namespace.camelize }.join("::") + "Controller" end end |
#to_s ⇒ Object
38 39 40 |
# File 'lib/rails_best_practices/core/routes.rb', line 38 def to_s "#{controller_name_with_namespaces}\##{action_name}" end |