erp_integration 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 17355e9b381181f43c54715c29142911d1c698961b9e83316725cdd7d15d0482
|
4
|
+
data.tar.gz: 0dc34879a850e7bcac51d5f5250d97ff4abba11bf49dffdc1e1526dc07e35fc0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7c20118ad5a092bafc6db0b98ca234055f03ec3aa468894389517091b56efab41bdc47b98b519be5dec7b8db286da52daee7167f287d91e9e31ff2765147a847
|
7
|
+
data.tar.gz: 3beffaa2d1c803448298f8023655a7653d4ad1f3ab14d7aa6a86279b2c8f831b1049f290cd6edfc6c42b151f861d03b341cdfe4e59c891ea554faed47d3d091a
|
@@ -1,17 +1,15 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative 'collection'
|
4
3
|
require_relative 'query_methods'
|
5
4
|
|
6
5
|
module ErpIntegration
|
7
6
|
module Fulfil
|
8
7
|
class ApiResource
|
8
|
+
include Enumerable
|
9
9
|
include QueryMethods
|
10
10
|
|
11
11
|
cattr_accessor :resource_klass, instance_accessor: false
|
12
|
-
|
13
12
|
delegate :client, :model_name, :resource_klass, to: 'self.class'
|
14
|
-
delegate_missing_to :all
|
15
13
|
|
16
14
|
def initialize(resource_klass)
|
17
15
|
self.class.resource_klass = resource_klass
|
@@ -20,17 +18,21 @@ module ErpIntegration
|
|
20
18
|
# The `where` and `includes` methods lazyly build a search/read query
|
21
19
|
# for Fulfil. By calling `all`, the prepared search/read query will actually
|
22
20
|
# be executed and the results will be fetched.
|
23
|
-
# @return [
|
21
|
+
# @return [Array] An enumerable collection object with all API results.
|
24
22
|
def all
|
25
23
|
return @results if defined?(@results)
|
26
24
|
|
27
|
-
@results =
|
25
|
+
@results =
|
28
26
|
client.put(
|
29
27
|
"model/#{model_name}/search_read",
|
30
28
|
Query.new(selected_fields, where_clauses)
|
31
|
-
)
|
32
|
-
|
33
|
-
|
29
|
+
).map { |item| resource_klass.new(item) }
|
30
|
+
end
|
31
|
+
|
32
|
+
# The `each` method turns the `ApiResource` instance into an enumerable object.
|
33
|
+
# For more information, see https://ruby-doc.org/core-3.0.2/Enumerable.html
|
34
|
+
def each(&block)
|
35
|
+
all.each(&block)
|
34
36
|
end
|
35
37
|
|
36
38
|
# The `client` exposes the `ErpIntegration::Fulfil::Client` to the class.
|
data/lib/erp_integration.rb
CHANGED
@@ -3,7 +3,6 @@
|
|
3
3
|
require 'active_support'
|
4
4
|
require 'active_support/core_ext/string/inflections'
|
5
5
|
require 'active_support/core_ext/module/delegation' # Allows using `delegate`
|
6
|
-
require 'active_support/core_ext/module/attribute_accessors' # Allows using `delegate_missing_to`
|
7
6
|
require 'faraday'
|
8
7
|
require 'faraday_middleware'
|
9
8
|
require 'json'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: erp_integration
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stefan Vermaas
|
@@ -257,7 +257,6 @@ files:
|
|
257
257
|
- lib/erp_integration/errors.rb
|
258
258
|
- lib/erp_integration/fulfil/api_resource.rb
|
259
259
|
- lib/erp_integration/fulfil/client.rb
|
260
|
-
- lib/erp_integration/fulfil/collection.rb
|
261
260
|
- lib/erp_integration/fulfil/query.rb
|
262
261
|
- lib/erp_integration/fulfil/query_methods.rb
|
263
262
|
- lib/erp_integration/fulfil/resources/order.rb
|
@@ -1,26 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module ErpIntegration
|
4
|
-
module Fulfil
|
5
|
-
# The `Collection` class provides an enumerable interface for the `ApiResource`
|
6
|
-
# to consume. It turns all the given items into the passed resource class.
|
7
|
-
#
|
8
|
-
# @example
|
9
|
-
# $ Collection.new([...], resource_klass: ErpIntegration::Order)
|
10
|
-
# # => <Collection @items=[<ErpIntegration::Order ... />, <ErpIntegration::Order ... />]
|
11
|
-
class Collection
|
12
|
-
include Enumerable
|
13
|
-
attr_reader :items
|
14
|
-
|
15
|
-
def initialize(items, resource_klass:)
|
16
|
-
@items = items.map { |item| resource_klass.new(item) }
|
17
|
-
end
|
18
|
-
|
19
|
-
# The `each` method turns the `Collection` instance into an enumerable object.
|
20
|
-
# For more information, see https://ruby-doc.org/core-3.0.2/Enumerable.html
|
21
|
-
def each(&block)
|
22
|
-
@items.each(&block)
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|