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
111 112 113 114 115 116 117 |
# File 'lib/remotable/adapters/active_resource.rb', line 111 def (path) if relative_path?(path) URI.join_url_segments(prefix, collection_name, "#{path}.#{format.extension}") else path end end |
#find_by(path) ⇒ Object
82 83 84 85 86 |
# File 'lib/remotable/adapters/active_resource.rb', line 82 def find_by(path) find_by!(path) rescue ::ActiveResource::ResourceNotFound nil end |
#find_by!(path) ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/remotable/adapters/active_resource.rb', line 88 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 SocketError, EOFError $!.extend Remotable::NetworkError raise rescue ::ActiveResource::TimeoutError $!.extend Remotable::TimeoutError raise rescue ::ActiveResource::ServerError $!.extend Remotable::ServiceUnavailableError if $!.response.code.to_i == 503 $!.extend Remotable::TimeoutError if $!.response.code.to_i == 504 raise rescue ::ActiveResource::SSLError $!.extend Remotable::SSLError 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.
68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/remotable/adapters/active_resource.rb', line 68 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.remote_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
58 59 60 |
# File 'lib/remotable/adapters/active_resource.rb', line 58 def new_resource new end |