No commit activity in last 3 years
No release in over 3 years
Makes information about a Rails application's resources (as defined via the 'resource(s)' routing DSL methods) available via Rails.application.resources
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

~> 2.1
= 3.0.0
 Project Readme

resource_awareness

resource_awareness makes information about a Rails application’s resources (as defined via the ‘resource/s’ routing DSL methods) available via Rails.application.resource_definitions. Each resource object encapsulates information such as the resource’s name, home route, path and the controller that is handling it:

attribute example
id post_comments
name comments
singular_name comment
home_route [the ‘post_comments’ named route]
path_prefix /posts/:post_id
path /posts/:post_id/comments
prefix_parameters [:post_id]
controller_path comments
controller CommentsController

Resources can be retrieved by id using bracket syntax:

Rails.application.resource_definitions['post_comments']

Controllers get a resource_definition instance method to controllers returning the resource they are handling, if any.

Resources have a to_xml method that makes it trivial to expose an application’s resource as a resource in turn:

# config/routes.rb
resources :resources

# app/controllers/resources_controller.rb
respond_to :xml

def index
  respond_with Rails.application.resource_definitions
end

# At this point, resource information is available at /resources.xml

Lastly, resource_awareness adds a rake resources tasks that lists an application’s resources, just like rake routes does for routes

Please note that resource_awareness is experimental and interfaces are likely to change. I very much welcome suggestions or comments!

Installation

gem install resource_awareness

Copyright © 2010 Ingo Weiss, released under the MIT license