e_plat 0.2.3 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3483b03e1f4725af9e8f8eb3b3b98f506212e0508ddb7536e917285eb35a3538
4
- data.tar.gz: ccd043d15ce417dd6713bccfcbbc59af215a1e2fbd1357b2b3954bd8b1a5e96d
3
+ metadata.gz: 6e070573b55b7ee4badc6e492bc04bf13f0edc534f937eaae8b0bafe5f78beea
4
+ data.tar.gz: e3c7a0b699e11057b08659bdcbe1c9c993d575b8e0ba7988f3f7cdd12c46e7ab
5
5
  SHA512:
6
- metadata.gz: 9cbcd506b0b37f159eb59032b98c7833436115e610e792b1770cfbc1151dbf9ae2a3749259edf175508371c4de283f65f61260239eb9a159d8e0c6641c6fe6de
7
- data.tar.gz: 82f0f4a8b4fc45d2694a60a460b765f0224971832ae2005629bf30b91d4eb4764a611bc77073771b02b70afcea9d27b13acbae8906df2cea6c461438a94c1ba3
6
+ metadata.gz: f80544f6fdf55208b4b8640631c0d39bc3c21b21dc8b1ee4bad3ebd3d56e343c3bf7164be655db8510bb62fc0cb5f3d8423b32e4f68b1ed47714ae02b312b373
7
+ data.tar.gz: 0c86da79e297bffad3c1348e92a2b69129298b82818beb4da1352610f1ff7efc0ac30fbe5d9df8a811a7ef7cef2fc989007b11946cbdc9bae2a1751f0452e839
data/README.md CHANGED
@@ -50,9 +50,7 @@ https://dev.to/doctolib/release-a-new-gem-version-je0
50
50
 
51
51
  ## Usage
52
52
 
53
- 1. Add `include EPlat::SessionState` to the top of your `ApplicationController` class.
54
-
55
- 2. To make requests, first initialize a session like so:
53
+ 1. To make requests, first initialize a session like so:
56
54
  ```ruby
57
55
  EPlat::Session.new(
58
56
  platform: :shopify,
@@ -62,12 +60,12 @@ EPlat::Session.new(
62
60
  )
63
61
  ```
64
62
 
65
- 3. You can then make requests to the platform via a singleton call on the class:
63
+ 2. You can then make requests to the platform via a singleton call on the Resource class:
66
64
  ```ruby
67
65
  EPlat::Product.find(id: 123)
68
66
  ```
69
67
 
70
- 4. Which will return an instance of:
68
+ 3. Which will return an instance of:
71
69
  ```ruby
72
70
  EPlat::Product
73
71
  ```
@@ -91,6 +89,7 @@ EPlat::Product
91
89
  </li>
92
90
  <li>
93
91
  The EPlat alias interface is just a set of dynamically created getter/setter/predicate methods with types that control the native attributes of the resource.
92
+ You can check if an attribute has been mapped by calling `@resource.mapped? "attribute_name"`
94
93
  </li>
95
94
  </ul>
96
95
  </ol>
data/lib/current.rb ADDED
@@ -0,0 +1,7 @@
1
+ class Current < ActiveSupport::CurrentAttributes
2
+ attribute :e_plat_session
3
+
4
+ def e_plat_session
5
+ super || EPlat::Client.new
6
+ end
7
+ end
@@ -1,7 +1,7 @@
1
1
 
2
2
  module EPlat
3
3
  class MissingSessionError < StandardError
4
- def initialize(msg="Missing session state, did you include EPlat::SessionState in your ApplicationController?")
4
+ def initialize(msg="Missing session state, did you set EPlat::Session")
5
5
  super
6
6
  end
7
7
  end
@@ -4,12 +4,11 @@ module EPlat
4
4
  class Base < ActiveResource::Base
5
5
 
6
6
  class << self
7
- include Dry::Effects.State(:e_plat_session)
8
7
  include Concerns::OverwriteRequestMethods
9
8
  threadsafe_attribute :client, :mapping, :include_root_in_json, :include_format_in_path
10
9
 
11
10
  def initialize_singleton!
12
- self.client = e_plat_session
11
+ self.client = Current.e_plat_session
13
12
 
14
13
  self.site = client.base_url
15
14
  self.prefix = client.url_prefix
@@ -37,13 +36,12 @@ module EPlat
37
36
  end
38
37
 
39
38
 
40
- include Dry::Effects.State(:e_plat_session)
41
39
  include Concerns::Aliases, Concerns::OverwriteInstanceMethods
42
40
 
43
41
  attr_accessor :client, :mapping, :mapped_attributes
44
42
 
45
43
  def initialize(attributes = {}, persisted = false)
46
- self.client = e_plat_session
44
+ self.client = Current.e_plat_session
47
45
  site = client.base_url
48
46
  self.mapping = mapping_instance
49
47
  ActiveResource::Base.include_root_in_json = client.shopify? && top_level_resource?
@@ -65,7 +65,7 @@ module EPlat
65
65
  class << self
66
66
 
67
67
  def element_path(id, prefix_options = {}, query_options = {})
68
- "#{ e_plat_session.url_prefix }shop.json"
68
+ "#{ Current.e_plat_session.url_prefix }shop.json"
69
69
  end
70
70
 
71
71
 
@@ -1,20 +1,17 @@
1
1
 
2
2
  module EPlat
3
3
  class Session
4
- include Dry::Effects.State(:e_plat_session)
5
- #the session is an instance of EPlat::Client made available via dry-effects
6
- # e_plat_session is an instance of EPlat::Client
7
-
8
-
9
- def initialize(platform:, store_url:, api_token:, store_hash: nil)
10
- e_plat_session.platform = platform
11
- e_plat_session.store_url = store_url
12
- e_plat_session.api_token = api_token
13
- e_plat_session.store_hash = store_hash
4
+ #the session is an instance of EPlat::Client made available via Rails Current::Attributes
5
+
6
+ def initialize(platform:, store_url:, api_token:, store_hash: nil)
7
+ Current.e_plat_session = EPlat::Client.new
8
+ Current.e_plat_session.platform = platform
9
+ Current.e_plat_session.store_url = store_url
10
+ Current.e_plat_session.api_token = api_token
11
+ Current.e_plat_session.store_hash = store_hash
14
12
 
15
- e_plat_session.send(:get_api_version) if e_plat_session.active?
16
- end
13
+ Current.e_plat_session.send(:get_api_version) if Current.e_plat_session.active?
14
+ end
17
15
 
18
-
19
16
  end
20
17
  end
data/lib/e_plat/types.rb CHANGED
@@ -1,7 +1,7 @@
1
1
 
2
2
  module EPlat
3
3
  module Types
4
- include Dry.Types()
4
+ include Dry.Types() #used in some typecasting
5
5
  end
6
6
  end
7
7
 
@@ -1,3 +1,3 @@
1
1
  module EPlat
2
- VERSION = "0.2.3"
2
+ VERSION = "0.3.0"
3
3
  end
data/lib/e_plat.rb CHANGED
@@ -5,7 +5,6 @@ require "zeitwerk"
5
5
  require "active_support"
6
6
  require "activeresource"
7
7
 
8
- require 'dry/effects'
9
8
  require 'dry-types'
10
9
  # require "e_plat/railtie" if defined?(Rails::Railtie)
11
10
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: e_plat
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - oliwoodsuk
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-05-18 00:00:00.000000000 Z
11
+ date: 2023-09-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -122,20 +122,6 @@ dependencies:
122
122
  - - ">="
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0'
125
- - !ruby/object:Gem::Dependency
126
- name: dry-effects
127
- requirement: !ruby/object:Gem::Requirement
128
- requirements:
129
- - - '='
130
- - !ruby/object:Gem::Version
131
- version: '0.4'
132
- type: :runtime
133
- prerelease: false
134
- version_requirements: !ruby/object:Gem::Requirement
135
- requirements:
136
- - - '='
137
- - !ruby/object:Gem::Version
138
- version: '0.4'
139
125
  - !ruby/object:Gem::Dependency
140
126
  name: webmock
141
127
  requirement: !ruby/object:Gem::Requirement
@@ -191,6 +177,7 @@ files:
191
177
  - app/assets/config/e_plat_manifest.js
192
178
  - config/routes.rb
193
179
  - lib/active_resource/schema.rb
180
+ - lib/current.rb
194
181
  - lib/e_plat.rb
195
182
  - lib/e_plat/client.rb
196
183
  - lib/e_plat/client/default_request_args.rb
@@ -225,7 +212,6 @@ files:
225
212
  - lib/e_plat/resource/product/variant.rb
226
213
  - lib/e_plat/resource/shop.rb
227
214
  - lib/e_plat/session.rb
228
- - lib/e_plat/session_state.rb
229
215
  - lib/e_plat/type_coercer.rb
230
216
  - lib/e_plat/types.rb
231
217
  - lib/e_plat/version.rb
@@ -1,25 +0,0 @@
1
-
2
- module EPlat
3
- module SessionState
4
- extend ActiveSupport::Concern
5
- include Dry::Effects::Handler.State(:e_plat_session)
6
-
7
- included do
8
- around_action :set_e_plat_session
9
- end
10
-
11
-
12
- private
13
-
14
- def set_e_plat_session
15
- with_e_plat_session(e_plat_session) { yield }
16
- end
17
-
18
- def e_plat_session
19
- # create empty client.
20
- # Will be populated later by EPlat::Session.new(..) if needed
21
- EPlat::Client.new()
22
- end
23
-
24
- end
25
- end