jodosha / acts-as-resource
- Source
- Commits
- Network (0)
- Issues (0)
- Downloads (1)
- Wiki (1)
- Graphs
-
Tree:
a66d887
commit a66d887956a08405c52868dc3d79b1db3628a39a
tree 9e8d284bd39ac9769c9609a43e4ec20e3ec8c0cf
parent 2b1fbac7ae503482447851d0a44f0f94c116cfbc
tree 9e8d284bd39ac9769c9609a43e4ec20e3ec8c0cf
parent 2b1fbac7ae503482447851d0a44f0f94c116cfbc
| name | age | message | |
|---|---|---|---|
| |
MIT-LICENSE | Tue May 13 05:08:02 -0700 2008 | |
| |
README | Tue May 13 05:13:41 -0700 2008 | |
| |
Rakefile | Tue May 13 05:08:02 -0700 2008 | |
| |
init.rb | Tue May 13 05:08:02 -0700 2008 | |
| |
install.rb | Tue May 13 05:08:02 -0700 2008 | |
| |
lib/ | Tue May 13 05:08:02 -0700 2008 | |
| |
tasks/ | Tue May 13 05:08:02 -0700 2008 | |
| |
test/ | Tue May 13 05:08:02 -0700 2008 | |
| |
uninstall.rb | Tue May 13 05:08:02 -0700 2008 |
README
ActsAsResource
==============
ActsAsResource combines ActiveRecord and ActiveResource features in *one* class.
Example
=======
class Carrot
acts_as_resource
self.site = 'http://localhost:3000'
belongs_to :bunny
validates_presence_of :color
validates_uniqueness_of :color
validates_length_of :color, :within => 2..23,
:if => lambda { |c| c.color && !c.color.empty? }
validates_format_of :color,
:with => /[\w\s]+$/,
:if => lambda { |c| c.color && !c.color.empty? }
before_create :please_call_me_before_create
def self.validate
logger.debug("VALIDATE #{color}")
end
def please_call_me_before_create
logger.debug("Ohhh, so you called me..")
end
end
Usage
=====
For convention each operation is *local* unless specified with :remote flag.
carrot = Carrot.find(23) # => local request
carrot = Carrot.find(23, :remote => false) # => local request
carrot = Carrot.find(23, :remote => true) # => remote request
Carrot.create(:color => 'orange') # => create local
Carrot.create(:color => 'orange', :remote => true) # => create remote
Prerequisites
=============
For 2.0 railists: no problem guys!
For old 1.2.x people you should live in the edge, cause ActiveResource is needed.
Install
=======
Rails 2.1.x
$ ./script/plugin install git://github.com/jodosha/acts-as-resource.git
Rails <= 2.0.x
$ ./script/plugin install http://dev.23labs.net/svn/rails/plugins/acts_as_resource
Uninstall
=========
$ ./script/plugin remove acts_as_resource
Common Issues
=============
* Actually ActsAsResource doesn't support Single Table Inheritance.
* Sometimes, when class relations are used, ActiveRecord generates a warning
like:
warning: toplevel constant Bunny referenced by Carrot::Bunny
Contribute
==========
* Check out the code and test it:
$ git clone git://github.com/jodosha/acts-as-resource.git
$ rake resource
* Create a ticket to: http://dev.23labs.net/rails/trac.cgi
* Create a patch and add as attachement to the ticket.
* The SVN repo has been deprecated in favor of the Git one.
Copyright (c) 2007-2008 Luca Guidi - http://lucaguidi.com, released under the MIT license