trophonius 1.0.1 → 1.0.2

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: c5bb1bd30a8503931d40b684cf3a6040491655dd6baafd6a13e91eaf0f63ba31
4
- data.tar.gz: ed842273ac9186e989410e19e4e211539b4b4cc7d38c2b69a3c865e8cce8e47a
3
+ metadata.gz: 46ff946aac98bf9fb8c0ca6494978e68d672f192221983faea8dd5246fd2444e
4
+ data.tar.gz: 1e8e038d4ea4fb5f2dededa7da2d69fa772f7f8570379957d768a1c5afd1590d
5
5
  SHA512:
6
- metadata.gz: 624497e5fc720fbd5ec40072b261665b654fd5a8e842309b0d45fe2214c9c4be9ea60162f0a489186e46d5373d7e735ab66d2d0794e437dd05d49178722f129b
7
- data.tar.gz: 1d95f28e907aa0f490b8f92195f0edeeb882f4a136be951ad373742805487e2a753de5a9ce9fac009ed2e04b5fef3ff29d617400c842cc2ddcd4afbf931f1902
6
+ metadata.gz: 58a38bedf53572f415b5fd204035d38840b3bc0be9a1985a12f1083843727451dee2a21b5e55c0a9f90331bb8afe9903e3db98e46d7e5afd3f5851dcce39e02a
7
+ data.tar.gz: 34cd621f24880fd6475d5bc350a18a18632e54f6fb4787637996c080c9123a561e6fdc177397528abf69bee9b5633bfa3360511864c5d729ae2748073de34233
@@ -148,18 +148,19 @@ module Trophonius
148
148
  hash.id = result["recordId"]
149
149
  hash.layout_name = layout_name
150
150
  result["fieldData"].keys.each do |key|
151
- unless key[/\s/] || key[/\W/]
152
- hash.send(:define_singleton_method, key.to_s) do
153
- hash[key]
154
- end
155
- unless non_modifiable_fields&.include?(key)
156
- @all_fields.merge!(key.to_s.downcase => key.to_s)
157
- hash.send(:define_singleton_method, "#{key.to_s}=") do |new_val|
158
- hash[key] = new_val
159
- hash.modifiable_fields[key] = new_val
160
- end
151
+ # unless key[/\s/] || key[/\W/]
152
+ hash.send(:define_singleton_method, ActiveSupport::Inflector.parameterize(ActiveSupport::Inflector.underscore(key.to_s), separator: '_')) do
153
+ hash[key]
154
+ end
155
+ unless non_modifiable_fields&.include?(key)
156
+ @all_fields.merge!(ActiveSupport::Inflector.parameterize(ActiveSupport::Inflector.underscore(key.to_s), separator: '_').downcase => ActiveSupport::Inflector.parameterize(ActiveSupport::Inflector.underscore(key.to_s), separator: '_'))
157
+ hash.send(:define_singleton_method, "#{ActiveSupport::Inflector.parameterize(ActiveSupport::Inflector.underscore(key.to_s), separator: '_')}=") do |new_val|
158
+ hash[key] = new_val
159
+ hash.modifiable_fields[key] = new_val
160
+ hash.modified_fields[key] = new_val
161
161
  end
162
162
  end
163
+ # end
163
164
  hash.merge!({key => result["fieldData"][key]})
164
165
  unless non_modifiable_fields&.include?(key)
165
166
  hash.modifiable_fields.merge!({key => result["fieldData"][key]})
@@ -167,13 +168,13 @@ module Trophonius
167
168
  end
168
169
  result["portalData"].keys.each do |key|
169
170
  unless key[/\s/] || key[/\W/]
170
- hash.send(:define_singleton_method, key.to_s) do
171
+ hash.send(:define_singleton_method, ActiveSupport::Inflector.parameterize(ActiveSupport::Inflector.underscore(key.to_s), separator: '_')) do
171
172
  hash[key]
172
173
  end
173
174
  end
174
175
  result["portalData"][key].each_with_index do |inner_hash|
175
176
  inner_hash.keys.each do |inner_key|
176
- inner_method = inner_key.gsub(/\w+::/, "")
177
+ inner_method = ActiveSupport::Inflector.parameterize(ActiveSupport::Inflector.underscore(inner_key.gsub(/\w+::/, "").to_s), separator: '_')
177
178
  unless inner_method[/\s/] || inner_method[/\W/]
178
179
  inner_hash.send(:define_singleton_method, inner_method.to_s) { inner_hash[inner_key] }
179
180
  inner_hash.send(:define_singleton_method, "id") { inner_hash["recordId"] }
@@ -6,12 +6,13 @@ module Trophonius
6
6
  #
7
7
  # A Record is contained in a RecordSet and has methods to retrieve data from the fields inside the Record-hash
8
8
  class Trophonius::Record < Hash
9
- attr_accessor :id, :layout_name, :modifiable_fields
9
+ attr_accessor :id, :layout_name, :modifiable_fields, :modified_fields
10
10
 
11
11
  ##
12
12
  # Initializes a new Record
13
13
  def initialize
14
14
  @modifiable_fields = {}
15
+ @modified_fields = {}
15
16
  end
16
17
 
17
18
  def []=(field, new_val)
@@ -26,7 +27,7 @@ module Trophonius
26
27
  # @return [True] if successful
27
28
  def save
28
29
  url = URI("http#{Trophonius.config.ssl == true ? 's' : ''}://#{Trophonius.config.host}/fmi/data/v1/databases/#{Trophonius.config.database}/layouts/#{layout_name}/records/#{id}")
29
- body = "{\"fieldData\": #{modifiable_fields.to_json}}"
30
+ body = "{\"fieldData\": #{modified_fields.to_json}}"
30
31
  response = Request.make_request(url, "Bearer #{Request.get_token}", 'patch', body)
31
32
  if response['messages'][0]['code'] != '0'
32
33
  Error.throw_error(response['messages'][0]['code'])
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trophonius
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kempen Automatisering