trophonius 2.1.5 → 2.1.7

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: 6ecc1055be56103548bd16bca808ff5a939e0ee7bbb2650d92f14cfb8e4d18da
4
- data.tar.gz: 5b7319bc6b276601a9208db83771f7e2b94c1a981d43f752f5af74370ddad44d
3
+ metadata.gz: b7e8354023ac2793edf55b987cb32151705e4e36d173e4ce543e85f18cb54cea
4
+ data.tar.gz: b8445ef34040269df2bcb9d6183359fa36107410126d2065707a76b768188125
5
5
  SHA512:
6
- metadata.gz: 2922556fcf044ffd33a83f7b2645d866e22f4be011813c833eecbb087e9563e9c9f15c72954645544ffc6bad2982b1f66057de0696f35febd3be9878f6bdf006
7
- data.tar.gz: bf26bdb6b2ce439f4d302fdd3075c9fc07d73acbdfe0dd0ec5981e2ebad5c2ef89735a69d419e812b77bc965f72f730c8fef1335fae0f04d8355d95597ef93d8
6
+ metadata.gz: ab653916b39228ed1de20c164d7aa9a1c1fd151ab1b9dac251efd827561e974b832c7ebbb080e2dc18719752ad2a6f2a9684abe32a088499fb4c934ac1797a6b
7
+ data.tar.gz: fcbb644e94eb52245bc2300f4b13307f2f707a451c2d1826fc94c4d1daaa9f02a800a1d40d5ff1d0a935603ee022d59bfbe6b0a1355145bec6175c00b2b9ff67
data/lib/config.rb CHANGED
@@ -1,7 +1,3 @@
1
- # require 'time'
2
- # require 'date_time'
3
- # require 'date'
4
-
5
1
  require 'active_support/configurable'
6
2
  require 'ethon'
7
3
 
@@ -30,5 +26,6 @@ module Trophonius
30
26
  config_accessor(:redis_no_verify) { false }
31
27
  config_accessor(:pool_size) { 5 }
32
28
  config_accessor(:debug) { false }
29
+ config_accessor(:callbacks) { { before_create: [], before_update: [], before_destroy: [], after_create: [], after_update: [], after_destroy: [] } }
33
30
  end
34
31
  end
@@ -171,7 +171,7 @@ module Trophonius
171
171
  # Tests whether the FileMaker token is still valid
172
172
  # @return [Boolean] True if the token is valid False if invalid
173
173
  def test_connection
174
- return last_connection.nil? || last_connection < Time.now - (15 * 60) if Trophonius.config.layout_name == ''
174
+ return !last_connection.nil? && last_connection > Time.now - (15 * 60) if Trophonius.config.layout_name == ''
175
175
 
176
176
  path = "/layouts/#{Trophonius.config.layout_name}/records?_limit=1"
177
177
  response =
data/lib/error.rb CHANGED
@@ -18,6 +18,7 @@ module Trophonius
18
18
  class FileError < StandardError; end # :nodoc:
19
19
  class CommandError < StandardError; end # :nodoc:
20
20
  class ConnectionError < StandardError; end # :nodoc:
21
+ class FileNotOpenError < StandardError; end # :nodoc:
21
22
  class EmptyFindError < StandardError; end # :nodoc:
22
23
  class ValidationError < StandardError; end # :nodoc:
23
24
  class DateValueError < ValidationError; end # :nodoc:
@@ -223,7 +224,9 @@ module Trophonius
223
224
  # when "738"
224
225
  # when "800"
225
226
  # when "801"
226
- # when "802"
227
+ when '802'
228
+ when '802'
229
+ raise FileNotOpenError.new, 'Could not open FileMaker file on server'
227
230
  # when "803"
228
231
  # when "804"
229
232
  # when "805"
data/lib/fm_date.rb CHANGED
@@ -1,3 +1,5 @@
1
+ require 'date'
2
+
1
3
  class Date
2
4
  def to_fm
3
5
  strftime('%m/%d/%Y')
data/lib/fm_date_time.rb CHANGED
@@ -1,3 +1,5 @@
1
+ require 'date'
2
+
1
3
  class DateTime
2
4
  def self.parse_fm_timestamp(timestamp)
3
5
  DateTime.strptime(timestamp, '%m/%d/%Y %H:%M:%S')
data/lib/fm_time.rb CHANGED
@@ -1,3 +1,6 @@
1
+ require 'date'
2
+ require 'time'
3
+
1
4
  class Time
2
5
  def to_fm
3
6
  strftime('%m-%d-%Y %H:%M:%S')
data/lib/model.rb CHANGED
@@ -37,10 +37,89 @@ module Trophonius
37
37
  @configuration.translations = {}
38
38
  @configuration.has_many_relations = {}
39
39
  @configuration.belongs_to_relations = {}
40
+ @configuration.callbacks = { before_create: [], before_update: [], before_destroy: [], after_create: [], after_update: [], after_destroy: [] }
40
41
  @offset = ''
41
42
  @limit = ''
42
43
  end
43
44
 
45
+ def self.scope(name, procedure, *_args)
46
+ define_singleton_method(name) do |*args|
47
+ procedure.arity.zero? ? procedure.call : procedure.call(*args)
48
+ end
49
+ end
50
+
51
+ def self.after_create(procedure, args)
52
+ @configuration.callbacks[:after_create].push({ name: procedure, args: args })
53
+ end
54
+
55
+ def self.run_after_create
56
+ @configuration.callbacks[:after_create].each do |callback|
57
+ procedure = callback[:name]
58
+ args = callback[:args]
59
+ procedure.is_a?(Proc) ? procedure.call(*args) : send(procedure, *args)
60
+ end
61
+ end
62
+
63
+ def self.after_update(procedure, args)
64
+ @configuration.callbacks[:after_update].push({ name: procedure, args: args })
65
+ end
66
+
67
+ def self.run_after_update
68
+ @configuration.callbacks[:after_update].each do |callback|
69
+ procedure = callback[:name]
70
+ args = callback[:args]
71
+ procedure.is_a?(Proc) ? procedure.call(*args) : send(procedure, *args)
72
+ end
73
+ end
74
+
75
+ def self.after_destroy(procedure, args)
76
+ @configuration.callbacks[:after_destroy].push({ name: procedure, args: args })
77
+ end
78
+
79
+ def self.run_after_destroy
80
+ @configuration.callbacks[:after_destroy].each do |callback|
81
+ procedure = callback[:name]
82
+ args = callback[:args]
83
+ procedure.is_a?(Proc) ? procedure.call(*args) : send(procedure, *args)
84
+ end
85
+ end
86
+
87
+ def self.before_create(procedure, args)
88
+ @configuration.callbacks[:before_create].push({ name: procedure, args: args })
89
+ end
90
+
91
+ def self.run_before_create
92
+ @configuration.callbacks[:before_create].each do |callback|
93
+ procedure = callback[:name]
94
+ args = callback[:args]
95
+ procedure.is_a?(Proc) ? procedure.call(*args) : send(procedure, *args)
96
+ end
97
+ end
98
+
99
+ def self.before_update(procedure, args)
100
+ @configuration.callbacks[:before_update].push({ name: procedure, args: args })
101
+ end
102
+
103
+ def self.run_before_update
104
+ @configuration.callbacks[:before_update].each do |callback|
105
+ procedure = callback[:name]
106
+ args = callback[:args]
107
+ procedure.is_a?(Proc) ? procedure.call(*args) : send(procedure, *args)
108
+ end
109
+ end
110
+
111
+ def self.before_destroy(procedure, args)
112
+ @configuration.callbacks[:before_destroy].push({ name: procedure, args: args })
113
+ end
114
+
115
+ def self.run_before_destroy
116
+ @configuration.callbacks[:before_destroy].each do |callback|
117
+ procedure = callback[:name]
118
+ args = callback[:args]
119
+ procedure.is_a?(Proc) ? procedure.call(*args) : send(procedure, *args)
120
+ end
121
+ end
122
+
44
123
  ##
45
124
  # Add a belongs to relationship.
46
125
  #
@@ -190,6 +269,7 @@ module Trophonius
190
269
  # Model.create(fieldOne: "Data")
191
270
  def self.create(field_data, portal_data: {})
192
271
  create_translations if @configuration.translations.keys.empty?
272
+ run_before_create
193
273
 
194
274
  field_data.transform_keys! { |k| (@configuration.translations[k.to_s] || k).to_s }
195
275
 
@@ -209,6 +289,8 @@ module Trophonius
209
289
  new_record = DatabaseRequest.make_request("/layouts/#{layout_name}/records/#{response['response']['recordId']}", 'get', '{}')
210
290
  record = build_result(new_record['response']['data'][0])
211
291
  record.send(:define_singleton_method, 'result_count') { 1 }
292
+ run_after_create
293
+
212
294
  record
213
295
  end
214
296
 
@@ -268,6 +350,7 @@ module Trophonius
268
350
 
269
351
  url = "layouts/#{layout_name}/records/#{record_id}"
270
352
  response = DatabaseRequest.make_request(url, 'delete', '{}')
353
+
271
354
  if response['messages'][0]['code'] == '0'
272
355
  true
273
356
  else
data/lib/record.rb CHANGED
@@ -22,13 +22,17 @@ module Trophonius
22
22
  @modifiable_fields = {}
23
23
  @modified_fields = {}
24
24
  @model_name = model
25
- @model = ActiveSupport::Inflector.constantize(ActiveSupport::Inflector.classify(ActiveSupport::Inflector.singularize(model_name)))
25
+ @model = model_name.instance_of?(String) ? ActiveSupport::Inflector.constantize(ActiveSupport::Inflector.classify(ActiveSupport::Inflector.singularize(model_name))) : model_name
26
26
  @layout_name = @model.layout_name
27
27
  define_field_methods(fm_record)
28
28
  define_portal_methods(fm_record)
29
29
  super()
30
30
  end
31
31
 
32
+ def to_param
33
+ record_id.to_s
34
+ end
35
+
32
36
  def []=(field, new_val)
33
37
  modifiable_fields[field] = new_val
34
38
  modified_fields[field] = new_val
@@ -182,8 +186,10 @@ module Trophonius
182
186
  def save
183
187
  url = "layouts/#{layout_name}/records/#{record_id}"
184
188
 
189
+ @model.run_before_update
185
190
  body = "{\"fieldData\": #{modified_fields.to_json}}"
186
191
  response = DatabaseRequest.make_request(url, 'patch', body)
192
+ @model.run_after_update
187
193
  response['messages'][0]['code'] == '0' ? true : Error.throw_error(response['messages'][0]['code'])
188
194
  end
189
195
 
@@ -195,7 +201,9 @@ module Trophonius
195
201
  def delete
196
202
  url = "layouts/#{layout_name}/records/#{record_id}"
197
203
 
204
+ @model.run_before_destroy
198
205
  response = DatabaseRequest.make_request(url, 'delete', '{}')
206
+ @model.run_after_destroy
199
207
  response['messages'][0]['code'] == '0' ? true : Error.throw_error(response['messages'][0]['code'])
200
208
  end
201
209
 
@@ -210,6 +218,7 @@ module Trophonius
210
218
  url = "layouts/#{layout_name}/records/#{record_id}"
211
219
  field_data.each_key { |field| modifiable_fields[field] = field_data[field] }
212
220
  field_data.transform_keys! { |k| (@model.translations[k.to_s] || k).to_s }
221
+ @model.run_before_update
213
222
 
214
223
  portal_data.each do |portal_name, values|
215
224
  values.map do |record|
@@ -232,6 +241,7 @@ module Trophonius
232
241
  return throw_field_missing(field_data) if code == '102'
233
242
  return Error.throw_error(code) if code != '0'
234
243
 
244
+ @model.run_after_update
235
245
  true
236
246
  end
237
247
 
data/lib/single.rb CHANGED
@@ -13,6 +13,14 @@ module Trophonius
13
13
  @all_fields = {}
14
14
  end
15
15
 
16
+ def non_modifiable_fields
17
+ []
18
+ end
19
+
20
+ def layout_name
21
+ @config[:layout_name]
22
+ end
23
+
16
24
  def where(fieldData)
17
25
  uri = URI::RFC2396_Parser.new
18
26
  url =
@@ -114,7 +122,7 @@ module Trophonius
114
122
  private
115
123
 
116
124
  def build_result(result)
117
- hash = Trophonius::Record.new(result, 'Single')
125
+ record = Trophonius::Record.new(result, self)
118
126
  record.layout_name = @config[:layout_name]
119
127
  record
120
128
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trophonius
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.5
4
+ version: 2.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kempen Automatisering
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-06-03 00:00:00.000000000 Z
11
+ date: 2024-10-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redis
@@ -98,7 +98,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
98
98
  - !ruby/object:Gem::Version
99
99
  version: '0'
100
100
  requirements: []
101
- rubygems_version: 3.5.5
101
+ rubygems_version: 3.4.7
102
102
  signing_key:
103
103
  specification_version: 4
104
104
  summary: Link between Ruby (on Rails) and FileMaker.