Sha256: 2f4fe7314e92a961a957e3ec54f175e186709d81453636df2c81ced69a1222a2

Contents?: true

Size: 795 Bytes

Versions: 17

Compression:

Stored size: 795 Bytes

Contents

module Madmin
  class Namespace
    def initialize(namespace)
      @namespace = namespace
    end

    def resources
      @resources ||= routes.map(&:first).uniq.map { |path|
        Resource.new(namespace, path)
      }
    end

    def routes
      @routes ||= all_routes.select { |controller, _action|
        controller.starts_with?("#{namespace}/")
      }.map { |controller, action|
        [controller.gsub(/^#{namespace}\//, ""), action]
      }
    end

    def resources_with_index_route
      routes.select { |_resource, route| route == "index" }.map(&:first).uniq
    end

    private

    attr_reader :namespace

    def all_routes
      Rails.application.routes.routes.map do |route|
        route.defaults.values_at(:controller, :action).map(&:to_s)
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
madmin-2.0.0 lib/madmin/namespace.rb
madmin-1.2.11 lib/madmin/namespace.rb
madmin-1.2.10 lib/madmin/namespace.rb
madmin-1.2.9 lib/madmin/namespace.rb
madmin-1.2.8 lib/madmin/namespace.rb
madmin-1.2.7 lib/madmin/namespace.rb
madmin-1.2.6 lib/madmin/namespace.rb
madmin-1.2.5 lib/madmin/namespace.rb
madmin-1.2.4 lib/madmin/namespace.rb
madmin-1.2.3 lib/madmin/namespace.rb
madmin-1.2.2 lib/madmin/namespace.rb
madmin-1.2.1 lib/madmin/namespace.rb
madmin-1.2.0 lib/madmin/namespace.rb
madmin-1.1.0 lib/madmin/namespace.rb
madmin-1.0.2 lib/madmin/namespace.rb
madmin-1.0.1 lib/madmin/namespace.rb
madmin-1.0.0 lib/madmin/namespace.rb