infopark_reactor 1.25.0 → 1.27.0.rc4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (129) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +25 -0
  3. data/.rubocop_todo.yml +363 -0
  4. data/Rakefile +10 -13
  5. data/app/models/rails_connector/abstract_obj.rb +2 -1
  6. data/config/routes.rb +0 -1
  7. data/infopark_reactor.gemspec +16 -15
  8. data/lib/generators/cm/migration/migration_generator.rb +4 -8
  9. data/lib/infopark_reactor.rb +43 -69
  10. data/lib/reactor/already_released.rb +1 -2
  11. data/lib/reactor/attributes.rb +94 -270
  12. data/lib/reactor/attributes/date_serializer.rb +20 -16
  13. data/lib/reactor/attributes/html_serializer.rb +6 -5
  14. data/lib/reactor/attributes/link_list_extender.rb +10 -8
  15. data/lib/reactor/attributes/link_list_from_accessor.rb +2 -1
  16. data/lib/reactor/attributes/link_list_from_attr_values.rb +2 -1
  17. data/lib/reactor/attributes/link_list_serializer.rb +8 -7
  18. data/lib/reactor/attributes_handlers.rb +164 -0
  19. data/lib/reactor/cache/permission.rb +6 -9
  20. data/lib/reactor/cache/user.rb +3 -6
  21. data/lib/reactor/cm/attribute.rb +16 -16
  22. data/lib/reactor/cm/attribute_group.rb +18 -21
  23. data/lib/reactor/cm/blob_too_small_error.rb +2 -2
  24. data/lib/reactor/cm/bridge.rb +6 -9
  25. data/lib/reactor/cm/channel.rb +3 -4
  26. data/lib/reactor/cm/editorial_group.rb +2 -9
  27. data/lib/reactor/cm/group.rb +30 -43
  28. data/lib/reactor/cm/job.rb +77 -0
  29. data/lib/reactor/cm/language.rb +21 -22
  30. data/lib/reactor/cm/link.rb +38 -40
  31. data/lib/reactor/cm/live_group.rb +2 -9
  32. data/lib/reactor/cm/log_entry.rb +22 -21
  33. data/lib/reactor/cm/missing_credentials.rb +3 -2
  34. data/lib/reactor/cm/multi_xml_request.rb +22 -25
  35. data/lib/reactor/cm/obj.rb +161 -152
  36. data/lib/reactor/cm/obj_class.rb +52 -51
  37. data/lib/reactor/cm/object_base.rb +26 -21
  38. data/lib/reactor/cm/permissions.rb +7 -7
  39. data/lib/reactor/cm/user.rb +63 -46
  40. data/lib/reactor/cm/workflow.rb +11 -12
  41. data/lib/reactor/cm/xml_attribute.rb +10 -19
  42. data/lib/reactor/cm/xml_markup.rb +7 -10
  43. data/lib/reactor/cm/xml_multi_request_error.rb +1 -3
  44. data/lib/reactor/cm/xml_request.rb +21 -29
  45. data/lib/reactor/cm/xml_request_error.rb +1 -3
  46. data/lib/reactor/cm/xml_response.rb +8 -16
  47. data/lib/reactor/cm/xml_single_request_error.rb +3 -5
  48. data/lib/reactor/configuration.rb +1 -3
  49. data/lib/reactor/engine.rb +5 -10
  50. data/lib/reactor/legacy.rb +8 -9
  51. data/lib/reactor/link/external.rb +8 -5
  52. data/lib/reactor/link/internal.rb +8 -5
  53. data/lib/reactor/link/temporary_link.rb +18 -19
  54. data/lib/reactor/main.rb +11 -15
  55. data/lib/reactor/migration.rb +52 -47
  56. data/lib/reactor/no_working_version.rb +1 -2
  57. data/lib/reactor/not_permitted.rb +1 -2
  58. data/lib/reactor/permission.rb +36 -38
  59. data/lib/reactor/persistence.rb +105 -159
  60. data/lib/reactor/plans/common_attribute.rb +7 -7
  61. data/lib/reactor/plans/common_attribute_group.rb +6 -6
  62. data/lib/reactor/plans/common_channel.rb +6 -6
  63. data/lib/reactor/plans/common_group.rb +7 -14
  64. data/lib/reactor/plans/common_job.rb +32 -0
  65. data/lib/reactor/plans/common_obj_class.rb +11 -11
  66. data/lib/reactor/plans/create_attribute.rb +1 -3
  67. data/lib/reactor/plans/create_attribute_group.rb +1 -3
  68. data/lib/reactor/plans/create_channel.rb +2 -3
  69. data/lib/reactor/plans/create_group.rb +3 -10
  70. data/lib/reactor/plans/create_job.rb +22 -0
  71. data/lib/reactor/plans/create_obj.rb +12 -14
  72. data/lib/reactor/plans/create_obj_class.rb +1 -2
  73. data/lib/reactor/plans/delete_attribute.rb +1 -3
  74. data/lib/reactor/plans/delete_attribute_group.rb +2 -4
  75. data/lib/reactor/plans/delete_channel.rb +4 -4
  76. data/lib/reactor/plans/delete_group.rb +2 -9
  77. data/lib/reactor/plans/delete_job.rb +23 -0
  78. data/lib/reactor/plans/delete_obj.rb +3 -4
  79. data/lib/reactor/plans/delete_obj_class.rb +1 -2
  80. data/lib/reactor/plans/prepared.rb +3 -4
  81. data/lib/reactor/plans/rename_group.rb +4 -11
  82. data/lib/reactor/plans/rename_obj_class.rb +1 -2
  83. data/lib/reactor/plans/update_attribute.rb +1 -3
  84. data/lib/reactor/plans/update_attribute_group.rb +2 -4
  85. data/lib/reactor/plans/update_group.rb +2 -9
  86. data/lib/reactor/plans/update_job.rb +27 -0
  87. data/lib/reactor/plans/update_obj.rb +6 -7
  88. data/lib/reactor/plans/update_obj_class.rb +0 -2
  89. data/lib/reactor/rc_independent.rb +0 -1
  90. data/lib/reactor/session.rb +27 -31
  91. data/lib/reactor/session/observers.rb +3 -5
  92. data/lib/reactor/session/user.rb +6 -7
  93. data/lib/reactor/session_helper/auth_filter.rb +9 -0
  94. data/lib/reactor/session_helper/auth_helper.rb +24 -0
  95. data/lib/reactor/session_helper/rsession_helper.rb +16 -0
  96. data/lib/reactor/session_helper/session_state.rb +31 -0
  97. data/lib/reactor/streaming_upload.rb +0 -1
  98. data/lib/reactor/sudo.rb +2 -3
  99. data/lib/reactor/support/link_matcher.rb +8 -7
  100. data/lib/reactor/tools/migrator.rb +30 -35
  101. data/lib/reactor/tools/response_handler/xml_attribute.rb +37 -27
  102. data/lib/reactor/tools/smart_xml_logger.rb +20 -22
  103. data/lib/reactor/tools/sower.rb +22 -23
  104. data/lib/reactor/tools/uploader.rb +12 -17
  105. data/lib/reactor/tools/versioner.rb +29 -30
  106. data/lib/reactor/tools/where_query.rb +12 -13
  107. data/lib/reactor/tools/workflow_generator.rb +26 -28
  108. data/lib/reactor/tools/xml_attributes.rb +7 -14
  109. data/lib/reactor/tools/xpath_extractor.rb +2 -1
  110. data/lib/reactor/validations.rb +20 -16
  111. data/lib/reactor/version.rb +1 -2
  112. data/lib/reactor/workflow.rb +10 -33
  113. data/lib/reactor/workflow/comment.rb +28 -0
  114. data/lib/reactor/workflow/empty.rb +0 -1
  115. data/lib/reactor/workflow/standard.rb +4 -3
  116. data/lib/tasks/cm_migrate.rake +3 -3
  117. data/lib/tasks/cm_seeds.rake +9 -16
  118. metadata +77 -35
  119. data/app/models/rails_connector/abstract_model.rb +0 -7
  120. data/app/models/rails_connector/attribute.rb +0 -94
  121. data/app/models/rails_connector/blob_mapping.rb +0 -16
  122. data/app/models/rails_connector/channel.rb +0 -41
  123. data/app/models/rails_connector/content.rb +0 -12
  124. data/app/models/rails_connector/obj_class.rb +0 -158
  125. data/app/models/rails_connector/obj_class_attr.rb +0 -5
  126. data/app/models/rails_connector/object_with_meta_data.rb +0 -18
  127. data/lib/rails_connector/meta/eager_loader.rb +0 -91
  128. data/lib/reactor/rails_connector_meta.rb +0 -149
  129. data/lib/reactor/session_helper.rb +0 -70
@@ -1,6 +1,5 @@
1
- # -*- encoding : utf-8 -*-
2
- require 'reactor/attributes/link_list_from_accessor'
3
- require 'reactor/attributes/link_list_from_attr_values'
1
+ require "reactor/attributes/link_list_from_accessor"
2
+ require "reactor/attributes/link_list_from_attr_values"
4
3
 
5
4
  module Reactor
6
5
  module Persistence
@@ -32,18 +31,18 @@ module Reactor
32
31
  # 3. object is invalid
33
32
  # 4. other error occoured
34
33
  # @param comment [String] comment to leave for the next user
35
- def release(comment=nil)
36
- return release!(comment)
34
+ def release(comment = nil)
35
+ release!(comment)
37
36
  rescue Reactor::Cm::XmlRequestError, ActiveRecord::RecordInvalid, Reactor::NotPermitted, Reactor::AlreadyReleased
38
- return false
37
+ false
39
38
  end
40
39
 
41
40
  # Removes the working version of the object,
42
41
  # if it exists
43
42
  # @param comment [String] comment to leave for the next user
44
43
  # @return [true]
45
- def revert(comment=nil)
46
- return revert!(comment)
44
+ def revert(comment = nil)
45
+ revert!(comment)
47
46
  end
48
47
 
49
48
  # Removes the working version of the object,
@@ -51,10 +50,10 @@ module Reactor
51
50
  # @param comment [String] comment to leave for the next user
52
51
  # @return [true]
53
52
  # @note There is no difference between #revert and #revert!
54
- def revert!(comment=nil)
53
+ def revert!(comment = nil)
55
54
  crul_obj.revert!(comment)
56
55
  reload
57
- return true
56
+ true
58
57
  end
59
58
 
60
59
  # Releases the object. Returns true on succes, can raise exceptions
@@ -62,13 +61,14 @@ module Reactor
62
61
  # @raise [Reactor::AlreadyReleased]
63
62
  # @raise [ActiveRecord::RecordInvalid] validations failed
64
63
  # @raise [Reactor::NotPermitted] current user lacks required permissions
65
- def release!(comment=nil)
64
+ def release!(comment = nil)
66
65
  run_callbacks(:release) do
67
- raise(Reactor::AlreadyReleased) unless self.really_edited?
66
+ raise(Reactor::AlreadyReleased) unless really_edited?
67
+
68
68
  crul_obj.release!(comment)
69
69
  reload
70
70
  end
71
- return true
71
+ true
72
72
  end
73
73
 
74
74
  # Makes the current user the editor of the object. Returns true when
@@ -78,11 +78,11 @@ module Reactor
78
78
  # 2. the object has not beed edited
79
79
  # 3. other error occured
80
80
  # @param comment [String] comment to leave for the next user
81
- def take(comment=nil)
81
+ def take(comment = nil)
82
82
  take!(comment)
83
- return true
83
+ true
84
84
  rescue Reactor::Cm::XmlRequestError, Reactor::NotPermitted, Reactor::NoWorkingVersion
85
- return false
85
+ false
86
86
  end
87
87
 
88
88
  # Makes the current user the editor of the object. Returns true when
@@ -90,13 +90,14 @@ module Reactor
90
90
  # @param comment [String] comment to leave for the next user
91
91
  # @raise [Reactor::NoWorkingVersion] there is no working version of the object
92
92
  # @raise [Reactor::NotPermitted] current user lacks required permissions
93
- def take!(comment=nil)
94
- raise(Reactor::NoWorkingVersion) unless self.really_edited?
93
+ def take!(comment = nil)
94
+ raise(Reactor::NoWorkingVersion) unless really_edited?
95
+
95
96
  # TODO: refactor the if condition
96
- crul_obj.take!(comment) if (crul_obj.editor != Reactor::Configuration::xml_access[:username])
97
+ crul_obj.take!(comment) if crul_obj.editor != Reactor::Configuration.xml_access[:username]
97
98
  # neccessary to recalculate #editor
98
99
  reload
99
- return true
100
+ true
100
101
  end
101
102
 
102
103
  # Creates a working version of the object. Returns true on success or when
@@ -104,41 +105,41 @@ module Reactor
104
105
  # @param comment [String] comment to leave for the next user
105
106
  # 1. user lacks the permissions
106
107
  # 2. other error occured
107
- def edit(comment=nil)
108
+ def edit(comment = nil)
108
109
  edit!(comment)
109
- return true
110
+ true
110
111
  rescue Reactor::Cm::XmlRequestError, Reactor::NotPermitted
111
- return false
112
+ false
112
113
  end
113
114
 
114
115
  # Creates a working version of the object. Returns true on success or when
115
116
  # the object already has a working version. Raises exceptions
116
117
  # @param comment [String] comment to leave for the next user
117
118
  # @raise [Reactor::NotPermitted] current user lacks required permissions
118
- def edit!(comment=nil)
119
- crul_obj.edit!(comment) unless self.really_edited?
119
+ def edit!(comment = nil)
120
+ crul_obj.edit!(comment) unless really_edited?
120
121
  reload
121
- return true
122
+ true
122
123
  end
123
124
 
124
125
  # Returns true, if the object has any links pointing to it.
125
126
  # @raise [Reactor::Cm::XmlRequestError] generic error occoured
126
127
  def has_super_links?
127
- crul_obj.get('hasSuperLinks') == '1'
128
+ crul_obj.get("hasSuperLinks") == "1"
128
129
  end
129
130
 
130
131
  # Return an array of RailsConnector::AbstractObj that contain a link
131
132
  # to this file.
132
133
  # @raise [Reactor::Cm::XmlRequestError] generic error occoured
133
134
  def super_objects
134
- RailsConnector::AbstractObj.where(:obj_id => crul_obj.get('superObjects')).to_a
135
+ RailsConnector::AbstractObj.where(obj_id: crul_obj.get("superObjects")).to_a
135
136
  end
136
137
 
137
138
  # Returns true if this object hasn't been saved yet -- that is, a record
138
139
  # for the object doesn't exist in the data store yet; otherwise, returns false.
139
140
  def new_record?
140
- #!destroyed? && (self.id.nil? || !self.class.exists?(self.id))
141
- !destroyed? && (self.id.nil? || self.path.blank?)
141
+ # !destroyed? && (self.id.nil? || !self.class.exists?(self.id))
142
+ !destroyed? && (id.nil? || path.blank?)
142
143
  end
143
144
 
144
145
  # Stolen from Rails 3.
@@ -172,7 +173,7 @@ module Reactor
172
173
  # Freezes the object.
173
174
  def destroy
174
175
  run_callbacks(:destroy) do
175
- self.delete
176
+ delete
176
177
  end
177
178
  end
178
179
 
@@ -181,12 +182,12 @@ module Reactor
181
182
  # but tries to mimmic their behaviour.
182
183
  def reload(options = nil)
183
184
  RailsConnector::AbstractObj.uncached do
184
- #super # Throws RecordNotFound when changing obj_class
185
+ # super # Throws RecordNotFound when changing obj_class
185
186
  # AR reload
186
187
  clear_aggregation_cache
187
188
  clear_association_cache
188
- fresh_object = RailsConnector::AbstractObj.find(self.id, options)
189
- @attributes = fresh_object.instance_variable_get('@attributes')
189
+ fresh_object = RailsConnector::AbstractObj.find(id, options)
190
+ @attributes = fresh_object.instance_variable_get("@attributes")
190
191
  @attributes_cache = {}
191
192
  # RC reload
192
193
  @attr_values = nil
@@ -207,9 +208,9 @@ module Reactor
207
208
  # 2. generic error occoured
208
209
  def resolve_refs
209
210
  resolve_refs!
210
- return true
211
+ true
211
212
  rescue Reactor::Cm::XmlRequestError, Reactor::NotPermitted
212
- return false
213
+ false
213
214
  end
214
215
 
215
216
  # Resolves references in any of the html fields. Returns true on success,
@@ -217,52 +218,39 @@ module Reactor
217
218
  # @raise [Reactor::NotPermitted] current user lacks required permissions
218
219
  def resolve_refs!
219
220
  crul_obj.resolve_refs!
220
- return true
221
- end
222
-
223
- if Reactor.rails3_0?
224
- # It should excactly match ActiveRecord::Base.new in it's behavior
225
- # @see ActiveRecord::Base.new
226
- def initialize(attributes = nil, &block)
227
- if true || !self.class.send(:attribute_methods_overriden?) # FIXME !!!!
228
- ignored_attributes = ignore_attributes(attributes)
229
- # supress block hijacking!
230
- super(attributes) {}
231
- load_ignored_attributes(ignored_attributes)
232
- yield self if block_given?
233
- else
234
- super(attributes)
235
- end
236
- end
237
- elsif Reactor.rails3_1? || Reactor.rails3_2? || Reactor.rails4_x?
238
- # It should excactly match ActiveRecord::Base.new in it's behavior
239
- # @see ActiveRecord::Base.new
240
- def initialize(attributes = nil, options={}, &block)
241
- if true || !self.class.send(:attribute_methods_overriden?) #FIXME !!!
242
- ignored_attributes = ignore_attributes(attributes)
243
- # supress block hijacking!
244
- super(attributes, options) {}
245
- load_ignored_attributes(ignored_attributes)
246
- yield self if block_given?
247
- else
248
- super(attributes, options)
249
- end
221
+ true
222
+ end
223
+
224
+ # It should excactly match ActiveRecord::Base.new in it's behavior
225
+ # @see ActiveRecord::Base.new
226
+ def initialize(attributes = nil, _options = {})
227
+ if true || !self.class.send(:attribute_methods_overriden?)
228
+ ignored_attributes = ignore_attributes(attributes)
229
+ # supress block hijacking!
230
+ super(attributes) {}
231
+ load_ignored_attributes(ignored_attributes)
232
+ yield self if block_given?
233
+ else
234
+ # TODO
235
+ # here we get 'ActiveRecord::AssociationTypeMismatch'
236
+ super(attributes)
250
237
  end
251
- else
252
- raise RuntimeError, "Unsupported Rails version!"
253
238
  end
254
239
 
255
240
  # Equivalent to Obj#edited?
256
241
  def really_edited?
257
- self.edited?
242
+ # check if really edited with curl request
243
+ crul_obj.edited?
244
+ # self.edited?
258
245
  end
259
246
 
260
247
  # Returns an array of errors
261
248
  def reasons_for_incomplete_state
262
- crul_obj.get('reasonsForIncompleteState') || []
249
+ crul_obj.get("reasonsForIncompleteState") || []
263
250
  end
264
251
 
265
252
  protected
253
+
266
254
  def prevent_resolve_refs
267
255
  @prevent_resolve_refs = true
268
256
  end
@@ -272,12 +260,10 @@ module Reactor
272
260
  end
273
261
 
274
262
  def sanitize_name
275
- return unless self.name.present?
263
+ return unless name.present?
276
264
 
277
- sanitized_name = self.class.send(:sanitize_name, self.name)
278
- if sanitized_name != self.name
279
- self.name = sanitized_name
280
- end
265
+ sanitized_name = self.class.send(:sanitize_name, name)
266
+ self.name = sanitized_name if sanitized_name != name
281
267
  end
282
268
 
283
269
  def crul_attributes_set?
@@ -289,13 +275,13 @@ module Reactor
289
275
  end
290
276
 
291
277
  def changed_linklists
292
- custom_attrs =
293
- self.singleton_class.send(:instance_variable_get, '@_o_allowed_attrs') ||
294
- self.class.send(:instance_variable_get, '@_o_allowed_attrs') ||
278
+ custom_attrs =
279
+ singleton_class.send(:instance_variable_get, "@_o_allowed_attrs") ||
280
+ self.class.send(:instance_variable_get, "@_o_allowed_attrs") ||
295
281
  []
296
282
 
297
283
  custom_attrs.select do |attr|
298
- self.send(:attribute_type, attr) == :linklist && self.send(:[],attr.to_sym).try(:changed?)
284
+ send(:attribute_type, attr) == :linklist && send(:[], attr.to_sym).try(:changed?)
299
285
  end
300
286
  end
301
287
 
@@ -312,28 +298,27 @@ module Reactor
312
298
  end
313
299
 
314
300
  def crul_obj_save
315
- attrs, _ = crul_attributes.partition do |field, (value, options)|
316
- self.send(:attribute_type, field) != :linklist
301
+ attrs, = crul_attributes.partition do |field, (_value, _options)|
302
+ send(:attribute_type, field) != :linklist
317
303
  end
318
304
  linklists = changed_linklists
319
305
 
320
306
  new_links = {}.tap do |result|
321
307
  linklists.map do |field|
322
308
  result[field] = Reactor::Attributes::LinkListFromAccessor.new(self, field).call.map do |l|
323
- {:link_id => l.id, :title => l.title, :destination_url => (l.internal? ? l.destination_object.path : l.url), :target => l.target}
309
+ { link_id: l.id, title: l.title, destination_url: (l.internal? ? l.destination_object.path : l.url), target: l.target }
324
310
  end
325
311
  end
326
312
  end
327
313
 
328
314
  links_modified = !linklists.empty?
329
315
 
330
- crul_obj.composite_save(attrs, [], [], [], links_modified) do |attrs, links_to_add, links_to_remove, links_to_set|
331
-
316
+ crul_obj.composite_save(attrs, [], [], [], links_modified) do |_attrs, links_to_add, links_to_remove, links_to_set|
332
317
  links_to_add.clear
333
318
  links_to_remove.clear
334
319
  links_to_set.clear
335
320
 
336
- copy = RailsConnector::AbstractObj.uncached { RailsConnector::AbstractObj.find(self.id) }
321
+ copy = RailsConnector::BasicObj.uncached { RailsConnector::BasicObj.find(id) }
337
322
 
338
323
  linklists.each do |linklist|
339
324
  original_link_ids = Reactor::Attributes::LinkListFromAttrValues.new(copy, linklist).call.map(&:id)
@@ -365,7 +350,6 @@ module Reactor
365
350
  end
366
351
  end
367
352
  end
368
-
369
353
  self.class.connection.clear_query_cache
370
354
  end
371
355
 
@@ -378,66 +362,55 @@ module Reactor
378
362
  # @param [String] new_name gives the object new name
379
363
  def copy(new_parent, recursive = false, new_name = nil)
380
364
  self.id = crul_obj.copy(RailsConnector::AbstractObj.path_from_anything(new_parent), recursive, new_name)
381
- #self.reload
382
- resolve_refs #?
383
- self.id
365
+ # self.reload
366
+ resolve_refs # ?
367
+ id
384
368
  end
385
369
 
386
370
  def trim_crul_attributes
387
- crul_attributes.delete_if {|attr, options| [:name, :objClass].include?(attr) }
371
+ crul_attributes.delete_if { |attr, _options| %i(name objClass).include?(attr) }
388
372
  end
389
373
 
390
374
  def crul_obj_create(name, parent, klass)
391
375
  @crul_obj = Reactor::Cm::Obj.create(name, parent, klass)
392
376
  end
393
377
 
378
+ # TODO: depends on rails version
394
379
  def create
395
380
  run_callbacks(:create) do
396
- c_name = self.name
397
- c_parent= self.class.path_from_anything(self.parent_obj_id)
398
- c_objcl = self.obj_class
381
+ c_name = name
382
+ c_parent = self.class.path_from_anything(parent_obj_id)
383
+ c_objcl = obj_class
399
384
  crul_obj_create(c_name, c_parent, c_objcl)
400
385
  self.id = @crul_obj.obj_id
401
386
  crul_obj_save if crul_attributes_set? || crul_links_changed?
402
- self.reload # ?
403
- self.id
387
+ reload # ?
388
+ changes_applied
389
+ id
404
390
  end
405
391
  end
406
392
 
407
- if Reactor.rails4_x?
408
- if Reactor.rails4_0_ge6? || Reactor.rails4_1? || Reactor.rails4_2?
409
- alias_method :_create_record, :create
410
- else
411
- alias_method :create_record, :create
412
- end
413
- end
414
-
415
- def update
416
- run_callbacks(:update) do
417
- crul_obj_save if crul_attributes_set? || crul_links_changed?
418
- self.reload
419
- self.id
420
- end
421
- end
393
+ alias_method :_create_record, :create
422
394
 
423
- if Reactor.rails4_x?
424
- if Reactor.rails4_0_ge6? || Reactor.rails4_1? || Reactor.rails4_2?
425
- alias_method :_update_record, :update
426
- else
427
- alias_method :update_record, :update
395
+ def update(_attribute_names = attribute_names)
396
+ run_callbacks(:update) do
397
+ crul_obj_save if crul_attributes_set? || crul_links_changed?
398
+ reload
399
+ changes_applied
400
+ id
428
401
  end
429
402
  end
430
403
 
404
+ alias_method :_update_record, :update
405
+
431
406
  def ignore_attributes(attributes)
432
407
  return {} if attributes.nil?
433
408
 
434
409
  obj_class = attributes.delete(:obj_class)
435
410
  parent = attributes.delete(:parent)
436
- {:obj_class => obj_class, :parent => parent}
411
+ { obj_class: obj_class, parent: parent }
437
412
  end
438
413
 
439
-
440
-
441
414
  def load_ignored_attributes(attributes)
442
415
  return if attributes.nil?
443
416
 
@@ -455,7 +428,6 @@ module Reactor
455
428
  self.obj_class = obj_class
456
429
  end
457
430
 
458
-
459
431
  # disables active record transactions
460
432
  def with_transaction_returning_status
461
433
  yield
@@ -469,44 +441,17 @@ module Reactor
469
441
  module ClassMethods
470
442
  def sanitize_name(old_name)
471
443
  if Reactor::Configuration.sanitize_obj_name
472
- character_map = {'ä' => 'ae', 'ö' => 'oe', 'ü' => 'ue', 'ß' => 'ss', 'Ä' => 'Ae', 'Ö' => 'Oe', 'Ü' => 'Ue'}
473
- new_name = old_name.gsub(/[^-$a-zA-Z0-9]/) {|char| character_map[char] || '_'}.
474
- gsub(/__+/,'_').
475
- gsub(/^_+/,'').
476
- gsub(/_+$/,'')
477
- new_name
444
+ character_map = { "ä" => "ae", "ö" => "oe", "ü" => "ue", "ß" => "ss", "Ä" => "Ae", "Ö" => "Oe", "Ü" => "Ue" }
445
+ old_name.gsub(/[^-$a-zA-Z0-9]/) { |char| character_map[char] || "_" }
446
+ .gsub(/__+/, "_")
447
+ .gsub(/^_+/, "")
448
+ .gsub(/_+$/, "")
449
+
478
450
  else
479
451
  old_name
480
452
  end
481
453
  end
482
454
 
483
- if Reactor.rails4_x?
484
- # Detect the subclass from the inheritance column of attrs. If the inheritance column value
485
- # is not self or a valid subclass, raises ActiveRecord::SubclassNotFound
486
- # If this is a StrongParameters hash, and access to inheritance_column is not permitted,
487
- # this will ignore the inheritance column and return nil
488
- def subclass_from_attrs(attrs)
489
- subclass_name = attrs.with_indifferent_access[inheritance_column]
490
-
491
- if subclass_name.present? && subclass_name != self.name
492
- subclass = subclass_name.safe_constantize
493
-
494
- if subclass # this if has been added
495
- unless descendants.include?(subclass)
496
- raise ActiveRecord::SubclassNotFound.new("Invalid single-table inheritance type: #{subclass_name} is not a subclass of #{name}")
497
- end
498
-
499
- subclass
500
- end
501
- end
502
- end
503
-
504
- if Reactor.rails4_0_ge6? || Reactor.rails4_1? || Reactor.rails4_2?
505
- alias_method :subclass_from_attributes, :subclass_from_attrs
506
- remove_method :subclass_from_attrs
507
- end
508
- end
509
-
510
455
  # Convenience method: it is equivalent to following call chain:
511
456
  #
512
457
  # i = create(attributes)
@@ -518,22 +463,23 @@ module Reactor
518
463
  #
519
464
  # image = Image.upload(File.open('image.jpg'), 'ext', :name => 'image', :parent => '/')
520
465
  #
521
- def upload(data_or_io, extension, attributes={})
466
+ def upload(data_or_io, extension, attributes = {})
522
467
  # Try to guess the object name from filename, if it's missing
523
- if (data_or_io.respond_to?(:path) && !attributes.key?(:name))
468
+ if data_or_io.respond_to?(:path) && !attributes.key?(:name)
524
469
  attributes[:name] = sanitize_name(File.basename(data_or_io.path, File.extname(data_or_io.path)))
525
470
  end
526
471
 
527
- instance = self.create!(attributes)# do |instance|
528
- instance.upload(data_or_io, extension)
529
- instance.save!
530
- #end
472
+ instance = create!(attributes) # do |instance|
473
+ instance.upload(data_or_io, extension)
474
+ instance.save!
475
+ # end
531
476
  instance
532
477
  end
533
478
 
534
479
  protected
480
+
535
481
  def attribute_methods_overriden?
536
- self.name != 'RailsConnector::AbstractObj'
482
+ name != "RailsConnector::BasicObj"
537
483
  end
538
484
  end
539
485
  end