ecoportal-api 0.10.7 → 0.10.8

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: f7d949e504087bf41e30ba17c20425eea599e744aae98456ba943f4433dd819e
4
- data.tar.gz: c382957de25cce7270caf6fa2615e731fc0aea94f67f43854ef339e97299461d
3
+ metadata.gz: e7809f3ff8865db913a9f1c26d2884057d4f9a585d4919d17a61326e264ebe12
4
+ data.tar.gz: 8816f23d52faf898a04f80c8ba283cf428684d5b3ad67cddbb7178c1280e81e2
5
5
  SHA512:
6
- metadata.gz: e0a7e3401365dff83f9b40aa6e11a812540748075dbce2592feac30c656096baa331817ba70b010cce951b5ca22f0abc12832192a144deff41ddc5f1cd1fc8cc
7
- data.tar.gz: 6ac12ae619ce68ea87819b020b2745f9de443abc90b3985f68123291e419d18e4286a6a3ba41debbe2586856fea1eab46aac572e835bc38e4a14e9bbd1813b7a
6
+ metadata.gz: d6eb969d3965fc9d86eacd1fa941178ca678b81ab528aa5c0b703bdec2a27866f191172d5f077fcc77638f6a39faeb03ab9394a8a901ca8dee5f65b5ae1c9003
7
+ data.tar.gz: 22ed539fbf7cae6d9336efc1b0816d3142c4fe6f6155a8e0d57a986c199b668bf67e3b3481c91889ff8aa99b70168316be195d2fa0f3d371e9a310d015305135
data/CHANGELOG.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file.
4
4
 
5
- ## [0.10.8] - 2024-11-xx
5
+ ## [0.10.9] - 2024-12-xx
6
6
 
7
7
  ### Added
8
8
 
@@ -10,6 +10,18 @@ All notable changes to this project will be documented in this file.
10
10
 
11
11
  ### Fixed
12
12
 
13
+ ## [0.10.8] - 2024-12-xx
14
+
15
+ ### Changed
16
+
17
+ - `Ecoportal::API::Common::BaseModel` tidy up code
18
+
19
+ ### Fixed
20
+
21
+ - `Ecoportal::API::V1::Job::Awaiter::Timer#time_left`
22
+ - To include `time_left_to_start` when not started.
23
+ - Remove call to `byebug`
24
+
13
25
  ## [0.10.7] - 2024-11-21
14
26
 
15
27
  ### Changed
@@ -17,9 +17,11 @@ module Ecoportal
17
17
  def passthrough(*methods, to: :doc)
18
18
  methods.each do |method|
19
19
  method = method.to_s
20
+
20
21
  define_method method do
21
22
  send(to)[method]
22
23
  end
24
+
23
25
  define_method "#{method}=" do |value|
24
26
  send(to)[method] = value
25
27
  end
@@ -36,6 +38,7 @@ module Ecoportal
36
38
  value = instance_variable_get(var)
37
39
  return value unless nullable
38
40
  return value if (value && doc[key]) || (!value && !doc[key])
41
+
39
42
  remove_instance_variable(var)
40
43
  end
41
44
 
@@ -44,8 +47,12 @@ module Ecoportal
44
47
  return instance_variable_set(var, nil) unless doc[key]
45
48
 
46
49
  self.class.resolve_class(klass).new(
47
- doc[key], parent: self, key: key
48
- ).tap {|obj| instance_variable_set(var, obj)}
50
+ doc[key],
51
+ parent: self,
52
+ key: key
53
+ ).tap do |obj|
54
+ instance_variable_set(var, obj)
55
+ end
49
56
  end
50
57
  end
51
58
  end
@@ -119,12 +126,16 @@ module Ecoportal
119
126
  end
120
127
 
121
128
  def dirty?
122
- as_update != {}
129
+ return false unless (json = as_update)
130
+ return false unless json.is_a?(Hash)
131
+
132
+ !json.empty?
123
133
  end
124
134
 
125
135
  # It consolidates all the changes carried by `doc` by setting it as `original_doc`.
126
136
  def consolidate!
127
- raise UnlinkedModel.new(from: "#{self.class}#consolidate!", key: _key) unless linked?
137
+ err = UnlinkedModel.new(from: "#{self.class}##{__method__}", key: _key)
138
+ raise err unless linked?
128
139
 
129
140
  new_doc = JSON.parse(doc.to_json)
130
141
  if is_root?
@@ -143,7 +154,9 @@ module Ecoportal
143
154
  def reset!(key = nil) # rubocop:disable Metrics/AbcSize>
144
155
  msg = "'key' should be a String. Given #{key}"
145
156
  raise ArgumentError, msg unless !key || key.is_a?(String)
146
- raise UnlinkedModel.new(from: "#{self.class}#reset!", key: _key) unless linked?
157
+
158
+ err = UnlinkedModel.new(from: "#{self.class}##{__method__}", key: _key)
159
+ raise err unless linked?
147
160
 
148
161
  if key
149
162
  if respond_to?(key) && (child = send(key)) && child.is_a?(Ecoportal::API::Common::BaseModel)
@@ -156,6 +169,7 @@ module Ecoportal
156
169
  end
157
170
  else
158
171
  new_doc = JSON.parse(original_doc.to_json)
172
+
159
173
  if is_root?
160
174
  @doc = new_doc
161
175
  else
@@ -61,7 +61,6 @@ module Ecoportal
61
61
  return unless @api_key.nil? || @api_key.match(/\A\W*\z/)
62
62
  return unless version
63
63
 
64
- byebug
65
64
  log(:error) { "Api-key missing!" }
66
65
  end
67
66
 
@@ -21,11 +21,7 @@ module Ecoportal
21
21
  end
22
22
 
23
23
  alias_method :original_start, :start
24
- # `start` time only counts from the moment that
25
- # it already started to progress
26
24
  def start
27
- return timestamp unless lstatus&.started?
28
-
29
25
  original_start || timestamp
30
26
  end
31
27
 
@@ -76,6 +72,10 @@ module Ecoportal
76
72
  end
77
73
 
78
74
  def time_left
75
+ (timeout_in - waited).round(2)
76
+ end
77
+
78
+ def time_left_total
79
79
  (timeout - waited).round(2)
80
80
  end
81
81
 
@@ -86,7 +86,7 @@ module Ecoportal
86
86
  end
87
87
 
88
88
  def timeout_in
89
- return time_left if started?
89
+ return time_left_total if started?
90
90
 
91
91
  time_left_to_start
92
92
  end
@@ -94,7 +94,7 @@ module Ecoportal
94
94
  # timeout library is evil. So we make poor-man timeout.
95
95
  # https://jvns.ca/blog/2015/11/27/why-rubys-timeout-is-dangerous-and-thread-dot-raise-is-terrifying/
96
96
  def timeout?
97
- !time_left.positive?
97
+ !time_left_total.positive?
98
98
  end
99
99
 
100
100
  def start_timeout?
@@ -140,7 +140,8 @@ module Ecoportal
140
140
  %i[total timeout start].each_with_object({}) do |key, kargs|
141
141
  kargs[key] = send(key)
142
142
  end.tap do |kargs|
143
- kargs[:start] = timestamp
143
+ kargs[:start] = start
144
+ kargs[:last] = timestamp
144
145
  kargs[:lstatus] = status
145
146
  end
146
147
  end
@@ -1,5 +1,5 @@
1
1
  module Ecoportal
2
2
  module API
3
- VERSION = '0.10.7'.freeze
3
+ VERSION = '0.10.8'.freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ecoportal-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.7
4
+ version: 0.10.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tapio Saarinen
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-11-20 00:00:00.000000000 Z
11
+ date: 2024-12-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pry