stbaldricks 4.2.0 → 4.2.1.alpha.1

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
  SHA1:
3
- metadata.gz: c94c5f49f5f3c5fda4ed688cef55f67fdfad14d3
4
- data.tar.gz: bc14f9659a826452313431588104d9bc517a187f
3
+ metadata.gz: 0784362d19e67df3927d5352bb4b8f736da8723b
4
+ data.tar.gz: bc015a08a87d033849587670fae45c652457e1b4
5
5
  SHA512:
6
- metadata.gz: 32856f5b3cb6a973fcd8753304f76ce51c069ba8f86c2e60f803f34b6ed29a257959ec79431a632c1a81faecd0e907a5f474fea6a2e6e597dcd1a3dfc8f61aa7
7
- data.tar.gz: 98e3052a8616492e38e080363444721b8cb2b3ac2b1370edf954aa97ced091d5e43b5d89319927777d7dbde65937f418180408d55f534a8b9b4ecc70c93f2187
6
+ metadata.gz: dba8fba1b0796641955d0bbb7ccc4c834638da1281c9093e30b24e45013833dcd8efa11c86468e0aa274c16f6ba2d48b2966ec8cec45b14ad22c94deecb41adb
7
+ data.tar.gz: e25f87c99fe3e5498f26c2480dd52c713b85789bd2c614e2fbbae1307ea122ea65b0cce1fc5287cb36945938d99205848da5aeacf2344c919adf1fd00c277c94
@@ -10,7 +10,7 @@ module SBF
10
10
  def save(entity_or_hash, with = {})
11
11
  if entity_or_hash.is_a?(SBF::Client::BaseEntity)
12
12
  return create(entity_or_hash, with) if entity_or_hash.id.nil?
13
- return update(entity_or_hash.id, entity_or_hash.year, entity_or_hash, with)
13
+ return update(entity_or_hash.id, entity_or_hash.year, entity_or_hash.update_data, with)
14
14
  else
15
15
  return create(entity_or_hash, with) if entity_or_hash[:id].nil?
16
16
  return update(entity_or_hash[:id], entity_or_hash[:year], entity_or_hash, with)
@@ -20,7 +20,7 @@ module SBF
20
20
  def save(entity_or_hash, with = {})
21
21
  if entity_or_hash.is_a?(SBF::Client::BaseEntity)
22
22
  return create(entity_or_hash, with) if entity_or_hash.id.nil?
23
- return update(entity_or_hash.id, entity_or_hash, with)
23
+ return update(entity_or_hash.id, entity_or_hash.update_data, with)
24
24
  else
25
25
  return create(entity_or_hash, with) if entity_or_hash[:id].nil?
26
26
  return update(entity_or_hash[:id], entity_or_hash, with)
@@ -229,6 +229,9 @@ module SBF
229
229
  data = entity_or_hash
230
230
  end
231
231
 
232
+ # Reload entity and its sub-entities so that no fields have a 'changed' state
233
+ data.reload_recursive
234
+
232
235
  return [data, nil]
233
236
  else
234
237
  data = entity_or_hash if entity_or_hash.is_a?(SBF::Client::BaseEntity)
@@ -11,6 +11,7 @@ require 'securerandom'
11
11
  module SBF
12
12
  module Client
13
13
  class BaseEntity
14
+ include ActiveModel::Dirty
14
15
  extend ActiveModel::Naming
15
16
  extend ActiveModel::Translation
16
17
  include ActiveModel::Conversion
@@ -45,6 +46,57 @@ module SBF
45
46
  true
46
47
  end
47
48
 
49
+ def reload!
50
+ # get the values from the persistence layer
51
+ clear_changes_information
52
+ end
53
+
54
+ def reload_recursive
55
+ instance_variables.each do |var|
56
+ attribute = instance_variable_get(var)
57
+ attribute.reload_recursive if attribute.is_a?(BaseEntity)
58
+ attribute.each { |a| a.reload_recursive if a.is_a?(BaseEntity) } if attribute.is_a?(Array)
59
+ end
60
+ reload!
61
+ end
62
+
63
+ def rollback!
64
+ restore_attributes
65
+ end
66
+
67
+ def update_data(with_keys = false)
68
+ data = {}
69
+ changes.each { |k, arr| data[k.to_sym] = arr[1] }
70
+
71
+ instance_variables.each do |var|
72
+ attribute = instance_variable_get(var)
73
+ if attribute.is_a?(BaseEntity)
74
+ if attribute.update_data.empty?
75
+ data.delete(var.to_s.gsub('@', '').to_sym)
76
+ else
77
+ data.merge!(var.to_s.gsub('@', '').to_sym => attribute.update_data(true))
78
+ end
79
+ elsif attribute.is_a?(Array)
80
+ selected = attribute.select { |a| a.is_a?(BaseEntity) || !attribute.update_data(true).empty? }
81
+ attributes = selected.map { |s| s.update_data(true) }.reject(&:empty?)
82
+ if attributes.empty?
83
+ data.delete(var.to_s.gsub('@', '').to_sym)
84
+ else
85
+ data.merge!(var.to_s.gsub('@', '').to_sym => attributes)
86
+ end
87
+ end
88
+ end
89
+
90
+ return data if data.empty?
91
+
92
+ with_keys ? keys_data.merge(data) : data
93
+ end
94
+
95
+ def keys_data
96
+ return {} unless respond_to?(:id)
97
+ is_a?(SBF::Client::Event) ? {id: id, year: year} : {id: id}
98
+ end
99
+
48
100
  def attributes=(data)
49
101
  data ||= {}
50
102
  data.each do |key, value|
@@ -174,13 +226,24 @@ module SBF
174
226
 
175
227
  def self.attr_writer(*vars)
176
228
  attributes.merge(vars)
177
- super(*vars)
229
+
230
+ vars.each do |attribute|
231
+ define_attribute_methods attribute
232
+ define_changing_attr_methods attribute
233
+ end
234
+
178
235
  add_boolean_methods(vars, true)
179
236
  end
180
237
 
181
238
  def self.attr_accessor(*vars)
182
239
  attributes.merge(vars)
183
240
  super(*vars)
241
+
242
+ vars.each do |attribute|
243
+ define_attribute_methods attribute
244
+ define_changing_attr_methods attribute, false, true
245
+ end
246
+
184
247
  add_boolean_methods(vars, true)
185
248
  end
186
249
  ###########################################################################################
@@ -296,11 +359,23 @@ module SBF
296
359
  split_attribute = attribute.to_s.split('is_')
297
360
  next if split_attribute.length <= 1
298
361
  define_method(:"#{split_attribute.last}?") { send(attribute) }
299
- define_method(:"#{attribute}=") { |val| instance_variable_set("@#{attribute}".to_sym, val.to_s.to_b) } if setter
362
+ define_changing_attr_methods(attribute, true) if setter
300
363
  end
301
364
  end
302
365
  private_class_method :add_boolean_methods
303
366
 
367
+ def self.define_changing_attr_methods(attribute, is_boolean = false, define_reader = false)
368
+ define_method(:"#{attribute}") do
369
+ instance_variable_get("@#{attribute}".to_sym)
370
+ end if define_reader
371
+
372
+ define_method(:"#{attribute}=") do |val|
373
+ send(:"#{attribute}_will_change!") unless val == instance_variable_get("@#{attribute}".to_sym)
374
+ instance_variable_set("@#{attribute}".to_sym, is_boolean ? val.to_s.to_b : val)
375
+ end
376
+ end
377
+ private_class_method :define_changing_attr_methods
378
+
304
379
  # Creates a private method which resolves the class type based on the class mappings and the value
305
380
  # rubocop:disable MethodLength
306
381
  def self.add_class_selector_method(attribute, class_mappings)
@@ -46,6 +46,11 @@ module SBF
46
46
  ORGANIZATION_FOUNDATION = 'foundation'
47
47
  end
48
48
 
49
+ module FundingType
50
+ CREDIT_CARD = 'credit_card'
51
+ PAYPAL = 'paypal'
52
+ end
53
+
49
54
  class FullParticipant < SBF::Client::FullParticipant
50
55
  attr_reader :model_type
51
56
 
@@ -140,6 +145,7 @@ module SBF
140
145
  attr_accessor :display_name
141
146
  attr_accessor :is_unrecognized
142
147
  attr_accessor :promotional_code
148
+ attr_accessor :funding_type
143
149
  entity_collection_attr_accessor :donations, 'SBF::Client::FullDonation', 'SBF::Client::PartialDonation'
144
150
  attr_accessor :created_at, :modified_at, :modified_by, :how_created, :past_due_at
145
151
 
@@ -1,5 +1,5 @@
1
1
  module SBF
2
2
  module Client
3
- VERSION = '4.2.0'
3
+ VERSION = '4.2.1.alpha.1'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stbaldricks
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.2.0
4
+ version: 4.2.1.alpha.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Firespring
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-09-15 00:00:00.000000000 Z
11
+ date: 2017-09-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -210,9 +210,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
210
210
  version: '0'
211
211
  required_rubygems_version: !ruby/object:Gem::Requirement
212
212
  requirements:
213
- - - ">="
213
+ - - ">"
214
214
  - !ruby/object:Gem::Version
215
- version: '0'
215
+ version: 1.3.1
216
216
  requirements: []
217
217
  rubyforge_project:
218
218
  rubygems_version: 2.6.12