wrapi 0.4.5 → 0.4.6

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: b2879998432bd9b2be748b54c21024a68acf5cdba01ecc3040c9e9da45f02268
4
- data.tar.gz: 63b482ee658b94a605f92faa52502efe1fa24bee5a918db27c773726f4a1e326
3
+ metadata.gz: 5b7bed56656363a708f42ca25752e0d7235e9172e479a929e2f0c42674f42197
4
+ data.tar.gz: 0d0ea9163649d1da64a89c37c548dbb657a98f74fd0da8e3eb871c6994afe8f7
5
5
  SHA512:
6
- metadata.gz: 4913f5e123c1a2211e1c57b2b66e5712d1920ac667e38740d5047134fcc178aa82c1a509652da6f23ee16c54396025ed0959a4b95438d4026a2589b28de4d90e
7
- data.tar.gz: 0772f0cdb948a5100df2f08a0fdaf356823f1fdfa0bb658817d3a3626540c54ec29cf92a9d1d4f83b2f957b990a73dce8c20bff8a537fd6e6c226aff7f956706
6
+ metadata.gz: 81cc81edf7e4e9cf2d6b0c837e599332dd717d0914b87aba76ce56da736cdd588a43b863dcf9196e7eec8c86fbfb1df5e5d6586292a5f58c619487f8b7952bff
7
+ data.tar.gz: d1e12b22efcaf3ba181dd62407f9acf4e15e2f45f7c03848d8c076763fdd94ad9904f3b3751bd5491a00a820e0bec8ffd53bef60e910e4f541b4df9a04ed1be3
data/CHANGELOG.md CHANGED
@@ -39,4 +39,7 @@
39
39
  - fix typo and implement clone for entities
40
40
 
41
41
  ## [0.4.5] - 2024-03-12
42
- - rafactorings code readability
42
+ - refactorings code readability
43
+
44
+ ## [0.4.6] - 2024-06-17
45
+ - fix issue with loading Entity from yaml
data/lib/wrapi/entity.rb CHANGED
@@ -4,25 +4,31 @@ module WrAPI
4
4
  # Defines HTTP request methods
5
5
  module Request
6
6
  class Entity
7
- attr_reader :attributes
8
-
9
7
  # factory method to create entity or array of entities
10
- def self.create(attributes)
11
- if attributes.is_a? Array
12
- Entity.entify(attributes)
8
+ def self.create(attr)
9
+ if attr.is_a? Array
10
+ Entity.entify(attr)
13
11
  else
14
- Entity.new(attributes) if attributes
12
+ Entity.new(attr) if attr
15
13
  end
16
14
  end
17
15
 
18
- def initialize(attributes)
19
- case attributes
16
+ def initialize(attr)
17
+ case attr
20
18
  when Hash
21
- @attributes = attributes.clone.transform_keys(&:to_s)
19
+ @attributes = attr.clone.transform_keys(&:to_s)
22
20
  else
23
- @attributes = attributes.clone
21
+ @attributes = attr.clone
24
22
  end
25
23
  end
24
+
25
+ def attributes
26
+ @attributes || {}
27
+ end
28
+
29
+ def attributes= val
30
+ @attributes = val || {}
31
+ end
26
32
 
27
33
  def method_missing(method_sym, *arguments, &block)
28
34
  # assignment
@@ -40,6 +46,7 @@ module WrAPI
40
46
  end
41
47
 
42
48
  def respond_to?(method_sym, include_private = false)
49
+ @attributes ||= {}
43
50
  if @attributes.include? method_sym.to_s
44
51
  true
45
52
  else
@@ -52,15 +59,15 @@ module WrAPI
52
59
  end
53
60
 
54
61
  def accessor(method)
55
- case @attributes[method]
56
- when Hash
57
- @attributes[method] = self.class.new(@attributes[method])
58
- when Array
59
- # make deep copy
60
- @attributes[method] = Entity.entify(@attributes[method])
61
- else
62
- @attributes[method]
63
- end
62
+ case @attributes[method]
63
+ when Hash
64
+ @attributes[method] = self.class.new(@attributes[method])
65
+ when Array
66
+ # make deep copy
67
+ @attributes[method] = Entity.entify(@attributes[method])
68
+ else
69
+ @attributes[method]
70
+ end
64
71
  end
65
72
 
66
73
  def clone
@@ -69,6 +76,11 @@ module WrAPI
69
76
  c
70
77
  end
71
78
 
79
+ def ==(other)
80
+ (self.class == other.class) && (self.attributes.eql? other.attributes)
81
+ end
82
+ alias eql? ==
83
+
72
84
  def self.entify(a)
73
85
  if ( a.count > 0 ) && ( a.first.is_a? Hash )
74
86
  a.dup.map do |item|
data/lib/wrapi/request.rb CHANGED
@@ -29,8 +29,7 @@ module WrAPI
29
29
  # inject headers...
30
30
  request_labda.call(req) if request_labda
31
31
  end
32
- if d = pager.class.data(response.body)
33
- d = Entity.create(d)
32
+ handle_data(response.body,pager) do |d|
34
33
  if block_given?
35
34
  yield(d)
36
35
  else
@@ -114,7 +113,12 @@ module WrAPI
114
113
  request.body = URI.encode_www_form(options) unless options.empty?
115
114
  end
116
115
  end
117
-
116
+ def handle_data(body,pager)
117
+ if d = pager.class.data(body)
118
+ d = Entity.create(d)
119
+ yield(d) if block_given?
120
+ end
121
+ end
118
122
  # add data to array and check if data itself is an array
119
123
  def add_data(result,data)
120
124
  if data.is_a? Array
data/lib/wrapi/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module WrAPI
4
- VERSION = '0.4.5'
4
+ VERSION = '0.4.6'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wrapi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.5
4
+ version: 0.4.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Janco Tanis
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-03-18 00:00:00.000000000 Z
11
+ date: 2024-07-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday