public
Description: ActsAsResource combines ActiveRecord and ActiveResource features in *one* class.
Homepage: http://www.lucaguidi.com/pages/acts_as_resource
Clone URL: git://github.com/jodosha/acts-as-resource.git
jodosha (author)
Wed May 14 14:21:18 -0700 2008
commit  db70870afd7392aedb16eb6e4ee2b39043574eae
tree    a9747d5766d39b17754d35e93563df05dafe0a42
parent  641c200ec70e1caf7b16124d8d04b79eefb58a23
acts-as-resource / README
100644 90 lines (60 sloc) 2.279 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
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