Class: Administrate::Namespace

Inherits:
Object
  • Object
show all
Defined in:
lib/administrate/namespace.rb,
lib/administrate/namespace/resource.rb

Defined Under Namespace

Classes: Resource

Instance Method Summary collapse

Constructor Details

#initialize(namespace) ⇒ Namespace

Returns a new instance of Namespace.



3
4
5
# File 'lib/administrate/namespace.rb', line 3

def initialize(namespace)
  @namespace = namespace.to_sym
end

Instance Method Details

#resourcesObject



7
8
9
10
11
# File 'lib/administrate/namespace.rb', line 7

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

#resources_with_index_routeObject



21
22
23
# File 'lib/administrate/namespace.rb', line 21

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

#routesObject



13
14
15
16
17
18
19
# File 'lib/administrate/namespace.rb', line 13

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