Module: Remotable::Adapters::ActiveResource::ClassMethods
- Defined in:
- lib/remotable/adapters/active_resource.rb
Constant Summary collapse
- IF_MODIFIED_SINCE =
"If-Modified-Since".freeze
Instance Method Summary collapse
- #expanded_path_for(path) ⇒ Object
- #find_by(path) ⇒ Object
- #find_by!(path) ⇒ Object
-
#find_by_for_local(local_record, path) ⇒ Object
This is always invoked by instance#fetch_remote_resource.
- #new_resource ⇒ Object
Instance Method Details
#expanded_path_for(path) ⇒ Object
96 97 98 99 100 101 102 |
# File 'lib/remotable/adapters/active_resource.rb', line 96 def (path) if relative_path?(path) URI.join_url_segments(prefix, collection_name, "#{path}.#{format.extension}") else path end end |
#find_by(path) ⇒ Object
73 74 75 76 77 |
# File 'lib/remotable/adapters/active_resource.rb', line 73 def find_by(path) find_by!(path) rescue ::ActiveResource::ResourceNotFound nil end |
#find_by!(path) ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/remotable/adapters/active_resource.rb', line 79 def find_by!(path) = (path) Remotable.logger.info "[remotable:#{name.underscore}] GET #{} (timeout: #{timeout})" find(:one, :from => ).tap do |resource| resource.remote_key_path = if resource end rescue ::ActiveResource::TimeoutError $!.extend Remotable::TimeoutError raise rescue ::ActiveResource::ServerError $!.extend Remotable::ServiceUnavailableError if $!.response.code == 503 $!.extend Remotable::TimeoutError if $!.response.code == 504 raise end |
#find_by_for_local(local_record, path) ⇒ Object
This is always invoked by instance#fetch_remote_resource. It expects to find a remote counterpart for a local resource. It should always return a NullRemote object that doesn’t alter the behavior of a normal model at all.
59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/remotable/adapters/active_resource.rb', line 59 def find_by_for_local(local_record, path) had_previous_value = headers.key?(IF_MODIFIED_SINCE) previous_value = headers[IF_MODIFIED_SINCE] headers[IF_MODIFIED_SINCE] = Remotable.http_format_time(local_record.updated_at) if local_record.accepts_not_modified? find_by(path) ensure if had_previous_value headers[IF_MODIFIED_SINCE] = previous_value else headers.delete(IF_MODIFIED_SINCE) end end |
#new_resource ⇒ Object
49 50 51 |
# File 'lib/remotable/adapters/active_resource.rb', line 49 def new_resource new end |