Module: EPlat::Concerns::OverwriteRequestMethods::ClassMethods
- Defined in:
- lib/e_plat/resource/concerns/overwrite_request_methods.rb
Instance Method Summary collapse
- #create(attributes = {}) ⇒ Object
- #delete(id, options = {}) ⇒ Object
- #exists?(id, options = {}) ⇒ Boolean
- #find(*arguments) ⇒ Object
- #find_by(params) ⇒ Object
- #instantiate_collection(collection, original_params = {}, prefix_options = {}) ⇒ Object
- #new(attributes = {}, persisted = false) ⇒ Object
- #update(attributes = {}) ⇒ Object
Instance Method Details
#create(attributes = {}) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/e_plat/resource/concerns/overwrite_request_methods.rb', line 56 def create(attributes = {}) client = EPlat::Current.e_plat_session cached_shopify_webhook_warning if cached_shopify_webhook? if client.platform_klass(self) client.platform_klass(self).create(attributes) else initialize_singleton! attributes = mapping.via_native_attributes_where_possible(attributes) super end end |
#delete(id, options = {}) ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/e_plat/resource/concerns/overwrite_request_methods.rb', line 83 def delete(id, = {}) client = EPlat::Current.e_plat_session cached_shopify_webhook_warning if cached_shopify_webhook? if client.platform_klass(self) client.platform_klass(self).delete(id, ) else initialize_singleton! super end end |
#exists?(id, options = {}) ⇒ Boolean
95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/e_plat/resource/concerns/overwrite_request_methods.rb', line 95 def exists?(id, = {}) client = EPlat::Current.e_plat_session cached_shopify_webhook_warning if cached_shopify_webhook? if client.platform_klass(self) client.platform_klass(self).exists?(id, ) else initialize_singleton! super end end |
#find(*arguments) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/e_plat/resource/concerns/overwrite_request_methods.rb', line 10 def find(*arguments) client = EPlat::Current.e_plat_session cached_shopify_webhook_warning if cached_shopify_webhook? if client.platform_klass(self) and not platform_specific_class? client.platform_klass(self).find(*arguments) else initialize_singleton! if arguments.second && arguments.second.is_a?(Hash) && arguments.second[:params] arguments.second[:params].merge!(client.try("#{element_name}_default_request_args") || {}) arguments.second[:params] = mapping.via_native_attributes_where_possible(arguments.second[:params]) else arguments << {params: (client.try("#{element_name}_default_request_args") || {}) } end super end end |
#find_by(params) ⇒ Object
30 31 32 |
# File 'lib/e_plat/resource/concerns/overwrite_request_methods.rb', line 30 def find_by(params) find(:all, params: params)&.first end |
#instantiate_collection(collection, original_params = {}, prefix_options = {}) ⇒ Object
34 35 36 37 |
# File 'lib/e_plat/resource/concerns/overwrite_request_methods.rb', line 34 def instantiate_collection(collection, original_params = {}, = {}) collection = collection["data"] if collection.is_a?(Hash) && collection["data"] super end |
#new(attributes = {}, persisted = false) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/e_plat/resource/concerns/overwrite_request_methods.rb', line 39 def new(attributes={}, persisted = false) if client.platform_klass(self) and not platform_specific_class? client.platform_klass(self).new(attributes, persisted) else initialize_singleton! self.mapping = EPlat::Mapping.new_instance(specifc_mapping: specifc_mapping_name, resource: nil) if attributes[mapping.native_top_key] attributes = attributes.send(*top_key_method(mapping.native_top_key)) end attributes = attributes.with_defaults(mapping.class::DEFAULT_VALUES) super end end |
#update(attributes = {}) ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/e_plat/resource/concerns/overwrite_request_methods.rb', line 69 def update(attributes = {}) client = EPlat::Current.e_plat_session cached_shopify_webhook_warning if cached_shopify_webhook? if client.platform_klass(self) client.platform_klass(self).update(attributes) else initialize_singleton! attributes = mapping.via_native_attributes_where_possible(attributes) super end end |