Coder Social home page Coder Social logo

ingoweiss / resource_awareness Goto Github PK

View Code? Open in Web Editor NEW
15.0 1.0 1.0 128 KB

Makes information about a Rails application's resources (as defined via the 'resource(s)' routing DSL methods) available via Rails.application.resources

Home Page: http://github.com/ingoweiss/resource_awareness

Ruby 100.00%

resource_awareness's Introduction

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

resource_awareness's People

Contributors

ingoweiss avatar

Stargazers

Angus H. avatar Michael Schiller avatar Matt Daubert avatar Maurizio De Magnis avatar Simon Chiu avatar Rob Lacey avatar  avatar victor christensen avatar MartinA avatar Yaroslav Markin avatar Sven Fuchs avatar Garret Alfert avatar Maxim Filatov avatar Michael Bumann avatar Jeremy Daer avatar

Watchers

 avatar

resource_awareness's Issues

Should be able to handle multiple resources with same controller

resource_awareness is exactly what I've been looking for for a long long time but I think it could be 1000% more useful if it supported multiple resource mappings per controller. Example - I have ClubsController and PeopleController. Clubs and People should both be able to create/edit Pages that belong to either a Club or Person. The PagesController should know (via resource_awareness) whether or not it was called from a Club or Person and which Club or Person it is (probably for assigning a polymorphic field).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.