Module: RemoteResource::Base
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/remote_resource/base.rb
Defined Under Namespace
Modules: ClassMethods
Constant Summary collapse
- OPTIONS =
[:base_url, :site, :headers, :version, :path_prefix, :path_postfix, :collection_prefix, :content_type, :collection, :collection_name, :root_element]
Class Method Summary collapse
Instance Method Summary collapse
- #assign_errors_from_response(response) ⇒ Object
- #assign_response(response) ⇒ Object
- #connection_options ⇒ Object
- #errors? ⇒ Boolean
- #handle_response(response) ⇒ Object
- #new_record? ⇒ Boolean
- #persisted? ⇒ Boolean
- #success? ⇒ Boolean
Class Method Details
.global_headers ⇒ Object
32 33 34 |
# File 'lib/remote_resource/base.rb', line 32 def self.global_headers Thread.current[:global_headers] ||= {} end |
.global_headers=(headers) ⇒ Object
28 29 30 |
# File 'lib/remote_resource/base.rb', line 28 def self.global_headers=(headers) Thread.current[:global_headers] = headers end |
Instance Method Details
#assign_errors_from_response(response) ⇒ Object
101 102 103 |
# File 'lib/remote_resource/base.rb', line 101 def assign_errors_from_response(response) assign_errors response. end |
#assign_response(response) ⇒ Object
97 98 99 |
# File 'lib/remote_resource/base.rb', line 97 def assign_response(response) @_response = response end |
#connection_options ⇒ Object
67 68 69 |
# File 'lib/remote_resource/base.rb', line 67 def @connection_options ||= RemoteResource::ConnectionOptions.new(self.class) end |
#errors? ⇒ Boolean
83 84 85 |
# File 'lib/remote_resource/base.rb', line 83 def errors? errors.present? end |
#handle_response(response) ⇒ Object
87 88 89 90 91 92 93 94 95 |
# File 'lib/remote_resource/base.rb', line 87 def handle_response(response) if response.unprocessable_entity? rebuild_resource_from_response(response).tap do |resource| resource.assign_errors_from_response response end else rebuild_resource_from_response(response) end end |
#new_record? ⇒ Boolean
75 76 77 |
# File 'lib/remote_resource/base.rb', line 75 def new_record? !persisted? end |
#persisted? ⇒ Boolean
71 72 73 |
# File 'lib/remote_resource/base.rb', line 71 def persisted? id.present? end |
#success? ⇒ Boolean
79 80 81 |
# File 'lib/remote_resource/base.rb', line 79 def success? _response.success? && !errors? end |