Module: Isomorfeus::Data::GenericInstanceApi
- Defined in:
- lib/isomorfeus/data/generic_instance_api.rb
Instance Method Summary collapse
- #changed? ⇒ Boolean
- #create(_already_saved: {}) ⇒ Object
-
#current_user ⇒ Object
RUBY_ENGINE.
- #destroy ⇒ Object
- #key ⇒ Object
- #key=(k) ⇒ Object
-
#loaded? ⇒ Boolean
RUBY_ENGINE.
- #promise_create ⇒ Object
- #promise_destroy ⇒ Object
-
#promise_reload ⇒ Object
reload must be implemented by mixin.
- #promise_save ⇒ Object
- #pub_sub_client ⇒ Object
- #ref_s ⇒ Object
- #reload ⇒ Object
- #revision ⇒ Object
- #save(_already_saved: {}) ⇒ Object
- #sid ⇒ Object
- #sid_s ⇒ Object
Instance Method Details
#changed? ⇒ Boolean
12 13 14 |
# File 'lib/isomorfeus/data/generic_instance_api.rb', line 12 def changed? @_changed end |
#create(_already_saved: {}) ⇒ Object
37 38 39 40 |
# File 'lib/isomorfeus/data/generic_instance_api.rb', line 37 def create promise_create self end |
#current_user ⇒ Object
RUBY_ENGINE
162 163 164 |
# File 'lib/isomorfeus/data/generic_instance_api.rb', line 162 def current_user Isomorfeus.current_user end |
#destroy ⇒ Object
61 62 63 64 |
# File 'lib/isomorfeus/data/generic_instance_api.rb', line 61 def destroy promise_destroy nil end |
#key ⇒ Object
4 5 6 |
# File 'lib/isomorfeus/data/generic_instance_api.rb', line 4 def key @key end |
#key=(k) ⇒ Object
8 9 10 |
# File 'lib/isomorfeus/data/generic_instance_api.rb', line 8 def key=(k) @key = k.to_s end |
#loaded? ⇒ Boolean
RUBY_ENGINE
103 104 105 |
# File 'lib/isomorfeus/data/generic_instance_api.rb', line 103 def loaded? Redux.fetch_by_path(*@_store_path) ? true : false end |
#promise_create ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/isomorfeus/data/generic_instance_api.rb', line 42 def promise_create data_hash = { instance: to_transport } data_hash.deep_merge!(included_items: included_items_to_transport) if respond_to?(:included_items_to_transport) class_name = self.class.name Isomorfeus::Transport.promise_send_path( 'Isomorfeus::Data::Handler::Generic', class_name, :create, data_hash).then do |agent| agent.process do |agnt| data = agnt.full_response[:data] if data.key?(class_name) && data[class_name].key?(@key) && data[class_name][@key].key?('new_key') @key = data[class_name][@key]['new_key'] @revision = data[class_name][@key]['revision'] if data[class_name][@key].key?('revision') _update_paths end _load_from_store! Isomorfeus.store.dispatch(type: 'DATA_LOAD', data: data) self end end end |
#promise_destroy ⇒ Object
66 67 68 |
# File 'lib/isomorfeus/data/generic_instance_api.rb', line 66 def promise_destroy self.class.promise_destroy(key: @key) end |
#promise_reload ⇒ Object
reload must be implemented by mixin
137 138 139 |
# File 'lib/isomorfeus/data/generic_instance_api.rb', line 137 def promise_reload self.class.promise_load!(key: @key, instance: self) end |
#promise_save ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/isomorfeus/data/generic_instance_api.rb', line 84 def promise_save data_hash = { instance: to_transport } data_hash.deep_merge!(included_items: included_items_to_transport) if respond_to?(:included_items_to_transport) class_name = self.class.name Isomorfeus::Transport.promise_send_path( 'Isomorfeus::Data::Handler::Generic', class_name, :save, data_hash).then do |agent| agent.process do |agnt| data = agnt.full_response[:data] if data.key?(class_name) && data[class_name].key?(@key) && data[class_name][@key].key?('new_key') @key = data[class_name][@key]['new_key'] @revision = data[class_name][@key]['revision'] if data[class_name][@key].key?('revision') _update_paths end _load_from_store! Isomorfeus.store.dispatch(type: 'DATA_LOAD', data: data) self end end end |
#pub_sub_client ⇒ Object
166 167 168 |
# File 'lib/isomorfeus/data/generic_instance_api.rb', line 166 def pub_sub_client Isomorfeus.pub_sub_client end |
#ref_s ⇒ Object
28 29 30 |
# File 'lib/isomorfeus/data/generic_instance_api.rb', line 28 def ref_s self.class.gen_ref_s(@key) end |
#reload ⇒ Object
70 71 72 73 |
# File 'lib/isomorfeus/data/generic_instance_api.rb', line 70 def reload self.class.promise_load!(key: @key, instance: self) self end |
#revision ⇒ Object
16 17 18 |
# File 'lib/isomorfeus/data/generic_instance_api.rb', line 16 def revision @_revision end |
#save(_already_saved: {}) ⇒ Object
79 80 81 82 |
# File 'lib/isomorfeus/data/generic_instance_api.rb', line 79 def save promise_save self end |
#sid ⇒ Object
20 21 22 |
# File 'lib/isomorfeus/data/generic_instance_api.rb', line 20 def sid [@class_name, @key] end |
#sid_s ⇒ Object
24 25 26 |
# File 'lib/isomorfeus/data/generic_instance_api.rb', line 24 def sid_s "[#{@class_name}|#{@key}]" end |