Permalink
Browse files

Update tests and rdoc

  • Loading branch information...
1 parent 32f38f9 commit 9f12b130518eda07f401581559f3c8a29ca267c7 Sjoerd Andringa committed Apr 8, 2009
Showing with 20 additions and 8 deletions.
  1. +13 −4 README.rdoc
  2. +5 −2 lib/has_remote.rb
  3. +1 −1 lib/has_remote/caching.rb
  4. +1 −1 spec/caching_spec.rb
View
@@ -7,22 +7,25 @@ which enables you to look for certain attributes remotely.
script/plugins install git://github.com/innovationfactory/has_remote.git
+Only if you require locally cached attributes and synchronization of those:
+
script/generate has_remote_migration
rake db:migrate
=== Examples
First make sure your records have a reference to a remote resource:
-
- add_column :users, :remote_id, :integer # Default is 'remote_id', but can be changed, see options for has_remote.
+ add_column :users, :remote_id, :integer
+
+The default key is 'remote_id', but this can be changed, see options for {has_remote}[link:classes/HasRemote/ClassMethods.html#M000007].
class User < ActiveRecord::Base
has_remote :site => 'http://people.local'
end
User.find(1).remote
- # => #<User::Remote:...> (ActiveResource instance)
+ # => #<User::Remote:...> (ActiveResource object)
User.find(1).remote.username
# => "User name from remote server"
@@ -40,6 +43,9 @@ has_remote optionally takes a block which can be used to specify remote attribut
If you don't need to instantiate a local record, calling the remote class directly is possible too:
+ User.remote_class
+ # => User::Remote (ActiveResource class)
+
User::Remote.find(1)
Note that the User::Remote class only exists if User is set up to have a remote and has been loaded.
@@ -55,7 +61,7 @@ The <tt>:through</tt> option enables you to specify your own ActiveResource clas
has_remote :through => "RemoteUser"
end
-See documentation for HasRemote::ClassMethods#has_remote for a description of all options.
+See documentation for {has_remote}[link:classes/HasRemote/ClassMethods.html#M000007] for a description of all options.
=== Caching attributes locally
@@ -76,6 +82,9 @@ ways of keeping the locally cached attributes in sync with their remote values.
1. Manual synchronization
2. Rake task hr:sync
+Synchronization automatically requests all remote resources that have been changed since the last successful synchronization.
+You may need to override {changed_remotes_since}[link:classes/HasRemote/Caching.html#M000004] in your model to match your host's REST API.
+
==== Manual synchronization
See HasRemote::Caching for more information on the available methods for triggering synchronization manually.
View
@@ -51,11 +51,14 @@ module ClassMethods
# User.find(1).remote.username
# # => "User name from remote server"
#
- # <tt>has_remote</tt> also takes a block which can be used to specify remote attributes:
+ # has_remote also takes a block which is passed in a HasRemote::Config object which can be used to specify
+ # remote attributes:
#
# class User < ActiveRecord::Base
# has_remote :site => '...' do |remote|
# remote.attribute :username
+ # remote.attribute :full_name, :local_cache => true
+ # remote.attribute :email_address, :as => :email
# end
# end
#
@@ -74,7 +77,7 @@ class << self
attr_reader :remote_class
attr_reader :remote_key
- def remote_attributes
+ def remote_attributes # :nodoc:
@remote_attributes ||= []
end
@@ -31,7 +31,7 @@ def cached_attributes
# the latest updated_at time of the last processed remote objects.
#
# You may need to override this method in your model to match your host's REST API or to change
- # the default time:
+ # the default time, e.g.:
#
# def self.changed_remotes_since(time = nil)
# time ||= 12.hours.ago
@@ -95,7 +95,7 @@
}
end
- it "should fail slitently" do
+ it "should do it silently" do
@failure.should_not raise_error
end

0 comments on commit 9f12b13

Please sign in to comment.