Sha256: 99ce1434cfa6439c3b625b233b8bff8495c9556be84d0704bf73af211a2ab9a2

Contents?: true

Size: 1.39 KB

Versions: 4

Compression:

Stored size: 1.39 KB

Contents

module KepplerFrontend
  module Views
    # Assets
    class RoutesHandler
      def initialize; end

      def list
        routes = KepplerFrontend::Engine.routes.routes
        routes.map do |route|
          setting = "#{route.defaults[:controller]}/" +
                    "#{route.defaults[:action]}"
          [ route.path.spec.to_s, 
            setting 
          ]
        end
      end
        
      def search_route(file)
        route = ''
        routes_lines.each do |line|
          if controller_and_action?(file, line)
            route = route_format(line)
          end
        end
        route
      end

      def route_method(file)
        method = ''
        routes_lines.each do |line|
          if controller_and_action?(file, line)
            method = line.split(' ').first
          end
        end
        method
      end

      private
      
      def routes_url
        'rockets/keppler_frontend/config/routes.rb'
      end

      def route_format(route)
        route = route.split(' ').second
        route.gsub!("'", '')
        route.gsub!(",", '')
      end

      def routes_lines
        File.readlines(routes_url)
      end
      
      def controller_and_action?(file, route)
        file = file.split('.').first
        controller = file.split('/').second
        action = file.split('/').last
        route.include?("app/#{controller}##{action}")
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
keppler-2.1.22 installer/core/rockets/keppler_frontend/app/services/keppler_frontend/views/routes_handler.rb
keppler-2.1.21 installer/core/rockets/keppler_frontend/app/services/keppler_frontend/views/routes_handler.rb
keppler-2.1.20 installer/core/rockets/keppler_frontend/app/services/keppler_frontend/views/routes_handler.rb
keppler-2.1.19 installer/core/rockets/keppler_frontend/app/services/keppler_frontend/views/routes_handler.rb