Module: RemoteResource::Base
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/remote_resource/base.rb
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
- #_response ⇒ Object
- #assign_errors_from_response(response) ⇒ Object
- #connection_options ⇒ Object
- #destroyed? ⇒ Boolean
- #errors? ⇒ Boolean
- #handle_response(response) ⇒ Object
- #new_record? ⇒ Boolean
- #persisted? ⇒ Boolean
- #persistence ⇒ Object
- #success? ⇒ Boolean
Class Method Details
.global_headers ⇒ Object
35 36 37 |
# File 'lib/remote_resource/base.rb', line 35 def self.global_headers RequestStore.store[:global_headers] ||= {} end |
.global_headers=(headers) ⇒ Object
31 32 33 |
# File 'lib/remote_resource/base.rb', line 31 def self.global_headers=(headers) RequestStore.store[:global_headers] = headers end |
Instance Method Details
#_response ⇒ Object
114 115 116 |
# File 'lib/remote_resource/base.rb', line 114 def _response warn '[DEPRECATION] `._response` is deprecated. Please use `.last_response` instead.' end |
#assign_errors_from_response(response) ⇒ Object
110 111 112 |
# File 'lib/remote_resource/base.rb', line 110 def assign_errors_from_response(response) assign_errors(response.errors) end |
#connection_options ⇒ Object
69 70 71 |
# File 'lib/remote_resource/base.rb', line 69 def @connection_options ||= RemoteResource::ConnectionOptions.new(self.class) end |
#destroyed? ⇒ Boolean
89 90 91 |
# File 'lib/remote_resource/base.rb', line 89 def destroyed? !!@destroyed end |
#errors? ⇒ Boolean
97 98 99 |
# File 'lib/remote_resource/base.rb', line 97 def errors? errors.present? end |
#handle_response(response) ⇒ Object
101 102 103 104 105 106 107 108 |
# File 'lib/remote_resource/base.rb', line 101 def handle_response(response) if response.unprocessable_entity? rebuild_resource_from_response(response) assign_errors_from_response(response) else rebuild_resource_from_response(response) end and self end |
#new_record? ⇒ Boolean
85 86 87 |
# File 'lib/remote_resource/base.rb', line 85 def new_record? !persisted? && !destroyed? end |
#persisted? ⇒ Boolean
77 78 79 80 81 82 83 |
# File 'lib/remote_resource/base.rb', line 77 def persisted? if destroyed? false else !!@persisted || id.present? end end |
#persistence ⇒ Object
73 74 75 |
# File 'lib/remote_resource/base.rb', line 73 def persistence self if persisted? end |
#success? ⇒ Boolean
93 94 95 |
# File 'lib/remote_resource/base.rb', line 93 def success? !!@success || (last_response.present? && last_response.success? && !errors?) end |