ecoportal-api 0.10.8 → 0.10.9

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.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +19 -2
  3. data/lib/ecoportal/api/common/base_class.rb +11 -12
  4. data/lib/ecoportal/api/common/base_model.rb +3 -3
  5. data/lib/ecoportal/api/common/batch_operation.rb +10 -10
  6. data/lib/ecoportal/api/common/batch_response.rb +1 -1
  7. data/lib/ecoportal/api/common/client/elastic_apm_integration.rb +9 -9
  8. data/lib/ecoportal/api/common/client/error/checks.rb +1 -1
  9. data/lib/ecoportal/api/common/client/with_retry.rb +1 -1
  10. data/lib/ecoportal/api/common/client.rb +13 -13
  11. data/lib/ecoportal/api/common/doc_helpers.rb +7 -6
  12. data/lib/ecoportal/api/common/hash_diff.rb +8 -5
  13. data/lib/ecoportal/api/common/logging.rb +1 -0
  14. data/lib/ecoportal/api/common/response.rb +1 -1
  15. data/lib/ecoportal/api/common/wrapped_response.rb +1 -1
  16. data/lib/ecoportal/api/internal/account.rb +18 -18
  17. data/lib/ecoportal/api/internal/people.rb +1 -1
  18. data/lib/ecoportal/api/internal/person.rb +24 -18
  19. data/lib/ecoportal/api/internal/person_details.rb +1 -1
  20. data/lib/ecoportal/api/internal/person_schema.rb +1 -1
  21. data/lib/ecoportal/api/internal/person_schemas.rb +1 -1
  22. data/lib/ecoportal/api/internal/policy_groups.rb +3 -2
  23. data/lib/ecoportal/api/internal/preferences.rb +13 -10
  24. data/lib/ecoportal/api/internal.rb +5 -5
  25. data/lib/ecoportal/api/logger.rb +8 -7
  26. data/lib/ecoportal/api/v1/job/awaiter/timer.rb +1 -0
  27. data/lib/ecoportal/api/v1/job/status.rb +2 -2
  28. data/lib/ecoportal/api/v1/job.rb +4 -4
  29. data/lib/ecoportal/api/v1/people.rb +12 -10
  30. data/lib/ecoportal/api/v1/person.rb +27 -15
  31. data/lib/ecoportal/api/v1/person_details.rb +7 -7
  32. data/lib/ecoportal/api/v1/person_schema.rb +5 -4
  33. data/lib/ecoportal/api/v1/person_schemas.rb +9 -6
  34. data/lib/ecoportal/api/v1/schema_field.rb +8 -8
  35. data/lib/ecoportal/api/v1/schema_field_value.rb +15 -15
  36. data/lib/ecoportal/api/v1.rb +4 -4
  37. data/lib/ecoportal/api/version.rb +1 -1
  38. data/lib/ecoportal/api.rb +9 -9
  39. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e7809f3ff8865db913a9f1c26d2884057d4f9a585d4919d17a61326e264ebe12
4
- data.tar.gz: 8816f23d52faf898a04f80c8ba283cf428684d5b3ad67cddbb7178c1280e81e2
3
+ metadata.gz: 6237e3c50a3316623f664b2f3fda405a276f893371f8ba4f194584374d9ed90f
4
+ data.tar.gz: 0f071968a7b8daf694b4553b55187d8c411beea2902e86079e0a4c39cb8b3693
5
5
  SHA512:
6
- metadata.gz: d6eb969d3965fc9d86eacd1fa941178ca678b81ab528aa5c0b703bdec2a27866f191172d5f077fcc77638f6a39faeb03ab9394a8a901ca8dee5f65b5ae1c9003
7
- data.tar.gz: 22ed539fbf7cae6d9336efc1b0816d3142c4fe6f6155a8e0d57a986c199b668bf67e3b3481c91889ff8aa99b70168316be195d2fa0f3d371e9a310d015305135
6
+ metadata.gz: 67041fe9ebed8775b42189a2d4128b82653ccdb81edf22d8a8e9d66c95c771cf8c89b248cc2cb6c05e6801b3f67a6c444f0836848e17e236bf34fec0345374f0
7
+ data.tar.gz: 9fbb30e945184be0183a0280c61c7cedd8fc223806764de9dfaf000a135e37f00f9ceeab81f734e5c71e6ed101301e2c166a9392227322af468ec61408402725
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.9] - 2024-12-xx
5
+ ## [0.10.10] - 2025-03-xx
6
6
 
7
7
  ### Added
8
8
 
@@ -10,7 +10,24 @@ 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
13
+ ## [0.10.9] - 2025-03-29
14
+
15
+ ### Added
16
+
17
+ - `Ecoportal::API::V1::Person`, added usability methods:
18
+ - `#archived?`
19
+ - `archive!`
20
+ - `unarchive!`
21
+
22
+ ### Changed
23
+
24
+ - Substantial code tidy up
25
+
26
+ ### Fixed
27
+
28
+ - `Ecoportal::API::V1::PersonSchemas#each` called without block was loosing the parameters.
29
+
30
+ ## [0.10.8] - 2024-12-16
14
31
 
15
32
  ### Changed
16
33
 
@@ -8,25 +8,24 @@ module Ecoportal
8
8
  end
9
9
 
10
10
  def class_resolver(name, klass)
11
- define_singleton_method(name) { resolve_class(klass) }
12
- define_method(name) { self.class.resolve_class(klass) }
11
+ define_singleton_method(name) { resolve_class(klass) }
12
+ define_method(name) { self.class.resolve_class(klass) }
13
13
  end
14
14
 
15
15
  def resolve_class(klass)
16
- @resolved ||= {}
16
+ @resolved ||= {}
17
17
  @resolved[klass] ||=
18
18
  case klass
19
- when Class
20
- klass
21
- when String
22
- Kernel.const_get(klass)
23
- when Symbol
24
- resolve_class(self.send(klass))
25
- else
26
- raise "Unknown class: #{klass}"
19
+ when Class
20
+ klass
21
+ when String
22
+ Kernel.const_get(klass)
23
+ when Symbol
24
+ resolve_class(send(klass))
25
+ else
26
+ raise "Unknown class: #{klass}"
27
27
  end
28
28
  end
29
-
30
29
  end
31
30
  end
32
31
  end
@@ -4,7 +4,7 @@ module Ecoportal
4
4
  module Common
5
5
  class BaseModel
6
6
  class UnlinkedModel < StandardError
7
- def initialize(msg = "Something went wrong when linking the document.", from: nil, key: nil)
7
+ def initialize(msg = 'Something went wrong when linking the document.', from: nil, key: nil)
8
8
  msg << " From: #{from}." if from
9
9
  msg << " key: #{key}." if key
10
10
  super(msg)
@@ -148,10 +148,10 @@ module Ecoportal
148
148
  # It removes all the changes carried by `doc` by restoring `original_doc` into `doc`.
149
149
  # @note
150
150
  # 1. When there are nullable properties, it may be required to apply `reset!` from the parent
151
- # i.e. `parent.reset!("child")` # when parent.child is `nil`
151
+ # i.e. `parent.reset!('child')` # when parent.child is `nil`
152
152
  # 2. In such a case, only immediate childs are allowed to be reset
153
153
  # @param key [String, Array<String>, nil] if given, it only resets the specified property
154
- def reset!(key = nil) # rubocop:disable Metrics/AbcSize>
154
+ def reset!(key = nil) # rubocop:disable Metrics/AbcSize
155
155
  msg = "'key' should be a String. Given #{key}"
156
156
  raise ArgumentError, msg unless !key || key.is_a?(String)
157
157
 
@@ -26,20 +26,20 @@ module Ecoportal
26
26
 
27
27
  def process_response(response)
28
28
  unless response.success?
29
- msg = "Error: total failure in batch operation."
29
+ msg = 'Error: total failure in batch operation.'
30
30
  log(:debug) { msg }
31
31
  raise msg
32
32
  end
33
33
 
34
- log(:debug) { "Processing batch responses" } if deep_logging?
34
+ log(:debug) { 'Processing batch responses' } if deep_logging?
35
35
 
36
36
  body_data(response.body).each.with_index do |subresponse, idx|
37
- status = subresponse["status"]
37
+ status = subresponse['status']
38
38
  method = @operations[idx][:method]
39
- body = subresponse["response"]
39
+ body = subresponse['response']
40
40
  callback = @operations[idx][:callback]
41
41
 
42
- if status == 200 && method == "GET"
42
+ if status == 200 && method == 'GET'
43
43
  batch_response = BatchResponse.new(status, body, @wrapper.new(body))
44
44
  log_batch_response(@operations[idx], batch_response)
45
45
 
@@ -57,7 +57,7 @@ module Ecoportal
57
57
  id = get_id(doc)
58
58
  @operations << {
59
59
  path: "#{@base_path}/#{CGI.escape(id)}",
60
- method: "GET",
60
+ method: 'GET',
61
61
  callback: block
62
62
  }
63
63
  end
@@ -67,7 +67,7 @@ module Ecoportal
67
67
  body = get_body(doc)
68
68
  @operations << {
69
69
  path: "#{@base_path}/#{CGI.escape(id)}",
70
- method: "PATCH",
70
+ method: 'PATCH',
71
71
  body: body,
72
72
  callback: block
73
73
  }
@@ -78,7 +78,7 @@ module Ecoportal
78
78
  body = get_body(doc)
79
79
  @operations << {
80
80
  path: "#{@base_path}/#{CGI.escape(id)}",
81
- method: "POST",
81
+ method: 'POST',
82
82
  body: body,
83
83
  callback: block
84
84
  }
@@ -88,7 +88,7 @@ module Ecoportal
88
88
  id = get_id(doc)
89
89
  @operations << {
90
90
  path: "#{@base_path}/#{CGI.escape(id)}",
91
- method: "DELETE",
91
+ method: 'DELETE',
92
92
  callback: block
93
93
  }
94
94
  end
@@ -97,7 +97,7 @@ module Ecoportal
97
97
  body = get_body(doc)
98
98
  @operations << {
99
99
  path: @base_path,
100
- method: "POST",
100
+ method: 'POST',
101
101
  body: body,
102
102
  callback: block
103
103
  }
@@ -22,7 +22,7 @@ module Ecoportal
22
22
  if success?
23
23
  each(&:print_pretty)
24
24
  else
25
- puts "Request failed."
25
+ puts 'Request failed.'
26
26
  end
27
27
  end
28
28
  end
@@ -31,13 +31,13 @@ module Ecoportal
31
31
  close_elastic_apm = proc do |_id|
32
32
  next unless ElasticAPM.running?
33
33
 
34
- puts "Stopping ElasticAPM service"
34
+ puts 'Stopping ElasticAPM service'
35
35
  ElasticAPM.stop
36
36
  rescue StandardError
37
37
  # Silent
38
38
  end
39
39
 
40
- ObjectSpace.define_finalizer("ElasticAPM", close_elastic_apm)
40
+ ObjectSpace.define_finalizer('ElasticAPM', close_elastic_apm)
41
41
 
42
42
  def elastic_apm_service
43
43
  return false if @disable_apm
@@ -57,19 +57,19 @@ module Ecoportal
57
57
  # http_compression: false,
58
58
  transaction_sample_rate: 0.1,
59
59
  transaction_max_spans: 100,
60
- span_frames_min_duration: "5ms"
60
+ span_frames_min_duration: '5ms'
61
61
  }.tap do |options|
62
62
  # next unless false
63
63
 
64
64
  # options.merge!({
65
65
  # log_level: ::Logger::DEBUG,
66
- # log_path: File.join('log', "elastic_apm.log")
66
+ # log_path: File.join('log', 'elastic_apm.log')
67
67
  # })
68
68
  end
69
69
  end
70
70
 
71
71
  def elastic_apm_url
72
- @elastic_apm_url ||= "https://".tap do |url|
72
+ @elastic_apm_url ||= 'https://'.tap do |url|
73
73
  url << elastic_apm_account_id.to_s
74
74
  url << ".#{elastic_apm_base_url}"
75
75
  url << ":#{elastic_apm_port}"
@@ -89,17 +89,17 @@ module Ecoportal
89
89
  end
90
90
 
91
91
  def elastic_apm_region
92
- @elastic_apm_region ||= ENV['ELASTIC_APM_REGION'] || "ap-southeast-2"
92
+ @elastic_apm_region ||= ENV['ELASTIC_APM_REGION'] || 'ap-southeast-2'
93
93
  end
94
94
 
95
95
  def elastic_apm_port
96
- @elastic_apm_port ||= ENV['ELASTIC_APM_PORT'] || "443"
96
+ @elastic_apm_port ||= ENV['ELASTIC_APM_PORT'] || '443'
97
97
  end
98
98
 
99
99
  def environment
100
- @environment ||= "unknown".tap do |value|
100
+ @environment ||= 'unknown'.tap do |value|
101
101
  next unless instance_variable_defined?(:@host)
102
- next unless (env = @host.gsub(".ecoportal.com", ''))
102
+ next unless (env = @host.gsub('.ecoportal.com', ''))
103
103
 
104
104
  value.clear << env
105
105
  end
@@ -25,7 +25,7 @@ module Ecoportal
25
25
  response.body.nil?.tap do |wrong|
26
26
  next unless wrong
27
27
 
28
- msg = "Received non json body in response "
28
+ msg = 'Received non json body in response '
29
29
  msg << "(#{response.src_body.class}):\n "
30
30
  msg << response.src_body
31
31
  puts msg
@@ -40,7 +40,7 @@ module Ecoportal
40
40
  return response unless some_unexpected_error?(response)
41
41
 
42
42
  # handle server errors (5xx) & server bugs (i.e. empty body)
43
- msg = "re-attempting (remaining: "
43
+ msg = 're-attempting (remaining: '
44
44
  msg << "#{remaining} attempts out of #{attempts})"
45
45
  log(:debug) { msg }
46
46
 
@@ -61,7 +61,7 @@ module Ecoportal
61
61
  return unless @api_key.nil? || @api_key.match(/\A\W*\z/)
62
62
  return unless version
63
63
 
64
- log(:error) { "Api-key missing!" }
64
+ log(:error) { 'Api-key missing!' }
65
65
  end
66
66
 
67
67
  # Sends an http `GET` request against the api version using `path` to complete the base url,
@@ -73,7 +73,7 @@ module Ecoportal
73
73
  # @option params [String] :q some text to search. Omit this parameter to target all the entries.
74
74
  # @return [Common::Reponse] the basic custom response object.
75
75
  def get(path, params: {})
76
- instrument("GET", path, params) do
76
+ instrument('GET', path, params) do
77
77
  request do |http|
78
78
  http.get(url_for(path), params: params)
79
79
  end
@@ -87,7 +87,7 @@ module Ecoportal
87
87
  # @param data [String] the body of the query in json format.
88
88
  # @return [Common::Reponse] the basic custom response object.
89
89
  def post(path, data:)
90
- instrument("POST", path, data) do
90
+ instrument('POST', path, data) do
91
91
  request do |http|
92
92
  http.post(url_for(path), json: data)
93
93
  end
@@ -101,7 +101,7 @@ module Ecoportal
101
101
  # @param data [String] the body of the query in json format.
102
102
  # @return [Common::Reponse] the basic custom response object.
103
103
  def patch(path, data:)
104
- instrument("PATCH", path, data) do
104
+ instrument('PATCH', path, data) do
105
105
  request do |http|
106
106
  http.patch(url_for(path), json: data)
107
107
  end
@@ -112,7 +112,7 @@ module Ecoportal
112
112
  # @param path [String] the tail that completes the url of the request.
113
113
  # @return [Common::Reponse] the basic custom response object.
114
114
  def delete(path)
115
- instrument("DELETE", path) do
115
+ instrument('DELETE', path) do
116
116
  request do |http|
117
117
  http.delete(url_for(path))
118
118
  end
@@ -143,10 +143,10 @@ module Ecoportal
143
143
  def base_request
144
144
  @base_request ||=
145
145
  case @version
146
- when "v2"
147
- HTTP.headers("X-ECOPORTAL-API-KEY" => @api_key).accept(:json)
146
+ when 'v2'
147
+ HTTP.headers('X-ECOPORTAL-API-KEY' => @api_key).accept(:json)
148
148
  else
149
- HTTP.headers("X-ApiKey" => @api_key).accept(:json)
149
+ HTTP.headers('X-ApiKey' => @api_key).accept(:json)
150
150
  end
151
151
  end
152
152
 
@@ -160,7 +160,7 @@ module Ecoportal
160
160
  private
161
161
 
162
162
  def instrument(method, path, data = nil, &block)
163
- raise "Expected block" unless block_given?
163
+ raise 'Expected block' unless block_given?
164
164
 
165
165
  start_time = Time.now.to_f
166
166
 
@@ -192,10 +192,10 @@ module Ecoportal
192
192
 
193
193
  # Logger interface.
194
194
  # @example:
195
- # log(:info) {"General information on what's going on"}
196
- # log(:warn) {"This is a warning that something is likely to have gone amiss"}
197
- # log(:error) {"Something went wrong"}
198
- # log(:fatal) {"An unrecoverable error has happend"}
195
+ # log(:info) {'General information on what's going on'}
196
+ # log(:warn) {'This is a warning that something is likely to have gone amiss'}
197
+ # log(:error) {'Something went wrong'}
198
+ # log(:fatal) {'An unrecoverable error has happend'}
199
199
  # @param level [Symbol] the level that the message should be logged.
200
200
  # @yield [] generates the message.
201
201
  # @yieldreturn [String] the generated message.
@@ -14,12 +14,13 @@ module Ecoportal
14
14
 
15
15
  def get_id(doc)
16
16
  id = nil
17
- id ||= doc.id if doc.respond_to?(:id)
18
- id ||= doc.external_id if doc.respond_to?(:external_id)
19
- id ||= doc["id"] if doc.is_a?(Hash)
20
- id ||= doc["external_id"] if doc.is_a?(Hash)
21
- id ||= doc if doc.is_a?(String)
22
- id or raise "No ID has been given!"
17
+ id ||= doc.id if doc.respond_to?(:id)
18
+ id ||= doc.external_id if doc.respond_to?(:external_id)
19
+ id ||= doc['id'] if doc.is_a?(Hash)
20
+ id ||= doc['external_id'] if doc.is_a?(Hash)
21
+ id ||= doc if doc.is_a?(String)
22
+
23
+ id or raise 'No ID has been given!'
23
24
  id
24
25
  end
25
26
  end
@@ -1,11 +1,11 @@
1
+ # rubocop:disable Naming/MethodParameterName
1
2
  module Ecoportal
2
3
  module API
3
4
  module Common
4
5
  module HashDiff
5
- ID_KEYS = %w[id]
6
+ ID_KEYS = %w[id].freeze
6
7
 
7
8
  class << self
8
-
9
9
  def diff(a, b, ignore: [])
10
10
  case a
11
11
  when Hash
@@ -14,16 +14,17 @@ module Ecoportal
14
14
  b_value = b && b[key]
15
15
  no_changes = (a_value == b_value) || ignore.include?(key)
16
16
  next if !ID_KEYS.include?(key) && no_changes
17
+
17
18
  diffed[key] = diff(a_value, b_value, ignore: ignore)
18
19
  diffed.delete(key) if diffed[key] == {}
19
20
  end
21
+
20
22
  # All keys are IDs, so it's actually blank
21
- if (diffed.keys - ID_KEYS).empty?
22
- return {}
23
- end
23
+ return {} if (diffed.keys - ID_KEYS).empty?
24
24
  end
25
25
  when Array
26
26
  return a unless b.is_a?(Array) && a.length == b.length
27
+
27
28
  a.map.with_index do |a_value, idx|
28
29
  b_value = b[idx]
29
30
  diff(a_value, b_value, ignore: ignore)
@@ -39,3 +40,5 @@ module Ecoportal
39
40
  end
40
41
  end
41
42
  end
43
+
44
+ # rubocop:enable Naming/MethodParameterName
@@ -3,6 +3,7 @@ module Ecoportal
3
3
  module Common
4
4
  module Logging
5
5
  private
6
+
6
7
  def default_logger
7
8
  Ecoportal::API::Logger.new
8
9
  end
@@ -22,7 +22,7 @@ module Ecoportal
22
22
 
23
23
  def print_pretty
24
24
  puts "Status: #{@status.code}"
25
- puts "Body:"
25
+ puts 'Body:'
26
26
  puts JSON.pretty_generate(@body)
27
27
  end
28
28
  end
@@ -41,7 +41,7 @@ module Ecoportal
41
41
  def print_pretty
42
42
  return each(&:print_pretty) if success?
43
43
 
44
- "Request failed."
44
+ 'Request failed.'
45
45
  end
46
46
  end
47
47
  end
@@ -11,11 +11,11 @@ module Ecoportal
11
11
 
12
12
  passthrough(*PROPERTIES.map(&:to_sym))
13
13
 
14
- class_resolver :preferences_class, "Ecoportal::API::Internal::Preferences"
15
- class_resolver :permissions_class, "Ecoportal::API::Internal::Permissions"
14
+ class_resolver :preferences_class, 'Ecoportal::API::Internal::Preferences'
15
+ class_resolver :permissions_class, 'Ecoportal::API::Internal::Permissions'
16
16
 
17
- embeds_one :permissions, key: "permissions_custom", klass: :permissions_class
18
- embeds_one :perms_merged, key: "permissions_merged", klass: :permissions_class
17
+ embeds_one :permissions, key: 'permissions_custom', klass: :permissions_class
18
+ embeds_one :perms_merged, key: 'permissions_merged', klass: :permissions_class
19
19
  embeds_one :preferences, klass: :preferences_class
20
20
 
21
21
  # Sets the `default_tag` of the user
@@ -32,60 +32,60 @@ module Ecoportal
32
32
  end
33
33
  value = value.upcase
34
34
  end
35
- doc["default_tag"] = value
35
+ doc['default_tag'] = value
36
36
  end
37
37
 
38
38
  # Sets the `policy_group_ids`
39
39
  # @note it preserves the original order
40
40
  # @param value [Array<String>] the policy group ids to be set.
41
41
  def policy_group_ids=(value)
42
- set_uniq_array_keep_order("policy_group_ids", value)
42
+ set_uniq_array_keep_order('policy_group_ids', value)
43
43
  end
44
44
 
45
45
  # @return [Array<String>] the policy group ids of this user.
46
46
  def policy_group_ids
47
- doc["policy_group_ids"] ||= []
47
+ doc['policy_group_ids'] ||= []
48
48
  end
49
49
 
50
50
  # Sets the `login_provider_ids`
51
51
  def login_provider_ids=(value)
52
- set_uniq_array_keep_order("login_provider_ids", value)
52
+ set_uniq_array_keep_order('login_provider_ids', value)
53
53
  end
54
54
 
55
55
  # @return [Array<String>] the login provider ids of this user.
56
56
  def login_provider_ids
57
- doc["login_provider_ids"] ||= []
57
+ doc['login_provider_ids'] ||= []
58
58
  end
59
59
 
60
60
  # Sets the `starred_ids`
61
61
  def starred_ids=(value)
62
- set_uniq_array_keep_order("starred_ids", value)
62
+ set_uniq_array_keep_order('starred_ids', value)
63
63
  end
64
64
 
65
65
  # @return [Array<String>] the starred page ids of this user.
66
66
  def starred_ids
67
- doc["starred_ids"] ||= []
67
+ doc['starred_ids'] ||= []
68
68
  end
69
69
 
70
70
  # It preserves the values of keys that are not defined in `value`.
71
71
  # @param value [Hash] the abilities that you want to update.
72
72
  def permissions_custom=(value)
73
- doc["permissions_custom"] ||= {}
74
- doc["permissions_custom"].merge!(value)
73
+ doc['permissions_custom'] ||= {}
74
+ doc['permissions_custom'].merge!(value)
75
75
  end
76
76
 
77
77
  # It preserves the values of keys that are not defined in `value`.
78
78
  # @param value [Hash] the preferences that you want to update.
79
79
  def preferences=(value)
80
- doc["preferences"] ||= {}
81
- doc["preferences"].merge!(value)
80
+ doc['preferences'] ||= {}
81
+ doc['preferences'].merge!(value)
82
82
  end
83
83
 
84
84
  def as_json
85
85
  super.tap do |hash|
86
- hash["permissions_custom"] = permissions.as_json
87
- hash["permissions_merged"] = perms_merged.as_json
88
- hash["preferences"] = preferences.as_json
86
+ hash['permissions_custom'] = permissions.as_json
87
+ hash['permissions_merged'] = perms_merged.as_json
88
+ hash['preferences'] = preferences.as_json
89
89
  end
90
90
  end
91
91
 
@@ -2,7 +2,7 @@ module Ecoportal
2
2
  module API
3
3
  class Internal
4
4
  class People < V1::People
5
- class_resolver :person_class, "Ecoportal::API::Internal::Person"
5
+ class_resolver :person_class, 'Ecoportal::API::Internal::Person'
6
6
  end
7
7
  end
8
8
  end
@@ -3,24 +3,27 @@ module Ecoportal
3
3
  class Internal
4
4
  # @attr account [Account, nil] the account of the person or `nil` if missing.
5
5
  class Person < V1::Person
6
- class_resolver :person_details_class, "Ecoportal::API::Internal::PersonDetails"
7
- class_resolver :person_account_class, "Ecoportal::API::Internal::Account"
6
+ class_resolver :person_details_class, 'Ecoportal::API::Internal::PersonDetails'
7
+ class_resolver :person_account_class, 'Ecoportal::API::Internal::Account'
8
8
  embeds_one :account, nullable: true, klass: :person_account_class
9
9
 
10
10
  def initialize(doc = {}, *args, **kargs, &block)
11
- super(doc, *args, **kargs, &block)
11
+ super
12
+
12
13
  @is_new = @prev_is_new = no_account_nor_details?(@doc)
13
14
  end
14
15
 
15
16
  def consolidate!
16
17
  @prev_is_new = @is_new
17
- @is_new = false
18
+ @is_new = false
19
+
18
20
  super
19
21
  end
20
22
 
21
23
  def reset!(*args)
22
24
  @is_new = @prev_is_new
23
- super(*args)
25
+
26
+ super
24
27
  end
25
28
 
26
29
  # @note
@@ -34,27 +37,28 @@ module Ecoportal
34
37
  # @return [Boolean] whether or not this entry is being created now (i.e. non existent on server)
35
38
  def new?(value = :original)
36
39
  return @is_new if value == :original
40
+
37
41
  no_account_nor_details?(initial_doc)
38
42
  end
39
43
 
40
44
  # @return [Boolean] if the account has been added to `doc`
41
45
  def account_added?(value = :original)
42
- ref_doc = (value == :original) ? original_doc : initial_doc
43
- !!account && !ref_doc["account"]
46
+ ref_doc = value == :original ? original_doc : initial_doc
47
+ !!account && !ref_doc['account']
44
48
  end
45
49
 
46
50
  # @return [Boolean] if the account has been removed from `doc`
47
51
  def account_removed?(value = :original)
48
- ref_doc = (value == :original) ? original_doc : initial_doc
49
- !account && !!ref_doc["account"]
52
+ ref_doc = value == :original ? original_doc : initial_doc
53
+ !account && !!ref_doc['account']
50
54
  end
51
55
 
52
56
  def as_json
53
- super.update("account" => account&.as_json)
57
+ super.update('account' => account&.as_json)
54
58
  end
55
59
 
56
60
  def as_update(ref = :last, ignore: [])
57
- super(ref, ignore: ignore | ["user_id", "permissions_merged", "prefilter"])
61
+ super(ref, ignore: ignore | %w[user_id permissions_merged prefilter])
58
62
  end
59
63
 
60
64
  # Sets the Account to the person, depending on the paramter received:
@@ -67,19 +71,20 @@ module Ecoportal
67
71
  def account=(value)
68
72
  case value
69
73
  when NilClass
70
- doc["account"] = nil
74
+ doc['account'] = nil
71
75
  when Internal::Account
72
- doc["account"] = JSON.parse(value.to_json)
76
+ doc['account'] = JSON.parse(value.to_json)
73
77
  when Hash
74
78
  user_id = account.user_id if account
75
- doc["account"] = value.slice(*Internal::Account::PROPERTIES)
76
- doc["account"]["user_id"] = user_id if user_id
79
+ doc['account'] = value.slice(*Internal::Account::PROPERTIES)
80
+ doc['account']['user_id'] = user_id if user_id
77
81
  else
78
82
  # TODO
79
83
  raise "Invalid set on account: Need nil, Account or Hash; got #{value.class}"
80
84
  end
81
- remove_instance_variable("@account") if defined?(@account)
82
- return account
85
+
86
+ remove_instance_variable('@account') if defined?(@account)
87
+ account
83
88
  end
84
89
 
85
90
  # Adds an empty account to the person.
@@ -93,7 +98,8 @@ module Ecoportal
93
98
 
94
99
  def no_account_nor_details?(value = @doc)
95
100
  return true unless value.is_a?(Hash)
96
- !value.key?("details") && !value.key?("account")
101
+
102
+ !value.key?('details') && !value.key?('account')
97
103
  end
98
104
  end
99
105
  end
@@ -2,7 +2,7 @@ module Ecoportal
2
2
  module API
3
3
  class Internal
4
4
  class PersonDetails < V1::PersonDetails
5
- class_resolver :schema_field_value_class, "Ecoportal::API::Internal::SchemaFieldValue"
5
+ class_resolver :schema_field_value_class, 'Ecoportal::API::Internal::SchemaFieldValue'
6
6
  end
7
7
  end
8
8
  end