Class: RailsBestPractices::Core::Route

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_best_practices/core/routes.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_nameObject (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_nameObject (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

#namespacesObject (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_namespacesObject



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_sObject



38
39
40
# File 'lib/rails_best_practices/core/routes.rb', line 38

def to_s
  "#{controller_name_with_namespaces}\##{action_name}"
end