Sha256: 6e90f13be79236a328d6de37f119ee1aa5e5af976fdc5a9a8a6a048e31fee3e2

Contents?: true

Size: 1012 Bytes

Versions: 9

Compression:

Stored size: 1012 Bytes

Contents

# encoding: utf-8
module RailsBestPractices
  module Core
    class Routes < Array
      # add a route.
      #
      # @param [Array] namesapces
      # @param [String] controller name
      # @param [String] action name
      def add_route(namespaces, controller_name, action_name)
        self << Route.new(namespaces, controller_name, action_name)
      end
    end

    class Route
      attr_reader :namespaces, :controller_name, :action_name

      def initialize(namespaces, controller_name, action_name)
        @namespaces = namespaces
        entities = controller_name.split('/')
        @namespaces += entities[0..-2] if entities.size > 1
        @controller_name = entities.last
        @action_name = action_name
      end

      def controller_name_with_namespaces
        namespaces.map { |namespace| "#{namespace.camelize}::" }.join("") + "#{controller_name.camelize}Controller"
      end

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

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
rails_best_practices-1.8.0 lib/rails_best_practices/core/routes.rb
rails_best_practices-1.7.2 lib/rails_best_practices/core/routes.rb
rails_best_practices-1.7.1 lib/rails_best_practices/core/routes.rb
rails_best_practices-1.7.0 lib/rails_best_practices/core/routes.rb
rails_best_practices-1.6.0 lib/rails_best_practices/core/routes.rb
rails_best_practices-1.5.3 lib/rails_best_practices/core/routes.rb
rails_best_practices-1.5.2 lib/rails_best_practices/core/routes.rb
rails_best_practices-1.5.1 lib/rails_best_practices/core/routes.rb
rails_best_practices-1.5.0 lib/rails_best_practices/core/routes.rb