infopark_reactor 1.26.1 → 1.27.0.rc10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (130) 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 +92 -268
  12. data/lib/reactor/attributes/date_serializer.rb +23 -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 +23 -25
  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 +159 -154
  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 +43 -51
  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 +6 -7
  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 +16 -17
  54. data/lib/reactor/main.rb +11 -15
  55. data/lib/reactor/migration.rb +52 -53
  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 +107 -179
  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 +6 -6
  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 +3 -4
  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 +3 -6
  76. data/lib/reactor/plans/delete_group.rb +2 -9
  77. data/lib/reactor/plans/delete_job.rb +3 -5
  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 +4 -8
  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 +27 -33
  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 +11 -14
  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 +72 -36
  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/job.rb +0 -14
  125. data/app/models/rails_connector/obj_class.rb +0 -158
  126. data/app/models/rails_connector/obj_class_attr.rb +0 -5
  127. data/app/models/rails_connector/object_with_meta_data.rb +0 -18
  128. data/lib/rails_connector/meta/eager_loader.rb +0 -91
  129. data/lib/reactor/rails_connector_meta.rb +0 -149
  130. data/lib/reactor/session_helper.rb +0 -72
@@ -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,30 +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
39
- end
40
-
41
- # Unreleases the object. Returns true on success,
42
- # false when one of the following occurs:
43
- # 1. user lacks the permissions
44
- # 2. the object is not released
45
- # 3. object is invalid
46
- # 4. other error occoured
47
- def unrelease(comment=nil)
48
- return unrelease!(comment)
49
- rescue Reactor::Cm::XmlRequestError, ActiveRecord::RecordInvalid, Reactor::NotPermitted
50
- return false
37
+ false
51
38
  end
52
39
 
53
40
  # Removes the working version of the object,
54
41
  # if it exists
55
42
  # @param comment [String] comment to leave for the next user
56
43
  # @return [true]
57
- def revert(comment=nil)
58
- return revert!(comment)
44
+ def revert(comment = nil)
45
+ revert!(comment)
59
46
  end
60
47
 
61
48
  # Removes the working version of the object,
@@ -63,10 +50,10 @@ module Reactor
63
50
  # @param comment [String] comment to leave for the next user
64
51
  # @return [true]
65
52
  # @note There is no difference between #revert and #revert!
66
- def revert!(comment=nil)
53
+ def revert!(comment = nil)
67
54
  crul_obj.revert!(comment)
68
55
  reload
69
- return true
56
+ true
70
57
  end
71
58
 
72
59
  # Releases the object. Returns true on succes, can raise exceptions
@@ -74,21 +61,14 @@ module Reactor
74
61
  # @raise [Reactor::AlreadyReleased]
75
62
  # @raise [ActiveRecord::RecordInvalid] validations failed
76
63
  # @raise [Reactor::NotPermitted] current user lacks required permissions
77
- def release!(comment=nil)
64
+ def release!(comment = nil)
78
65
  run_callbacks(:release) do
79
- raise(Reactor::AlreadyReleased) unless self.really_edited?
66
+ raise(Reactor::AlreadyReleased) unless edited_or_committed?
67
+
80
68
  crul_obj.release!(comment)
81
69
  reload
82
70
  end
83
- return true
84
- end
85
-
86
- # Unreleases the object. Returns true on succes, can raise exceptions
87
- # @param comment [String] comment to leave for the next user
88
- def unrelease!(comment=nil)
89
- crul_obj.unrelease!(comment)
90
- reload
91
- return true
71
+ true
92
72
  end
93
73
 
94
74
  # Makes the current user the editor of the object. Returns true when
@@ -98,11 +78,11 @@ module Reactor
98
78
  # 2. the object has not beed edited
99
79
  # 3. other error occured
100
80
  # @param comment [String] comment to leave for the next user
101
- def take(comment=nil)
81
+ def take(comment = nil)
102
82
  take!(comment)
103
- return true
83
+ true
104
84
  rescue Reactor::Cm::XmlRequestError, Reactor::NotPermitted, Reactor::NoWorkingVersion
105
- return false
85
+ false
106
86
  end
107
87
 
108
88
  # Makes the current user the editor of the object. Returns true when
@@ -110,13 +90,14 @@ module Reactor
110
90
  # @param comment [String] comment to leave for the next user
111
91
  # @raise [Reactor::NoWorkingVersion] there is no working version of the object
112
92
  # @raise [Reactor::NotPermitted] current user lacks required permissions
113
- def take!(comment=nil)
114
- raise(Reactor::NoWorkingVersion) unless self.really_edited?
93
+ def take!(comment = nil)
94
+ raise(Reactor::NoWorkingVersion) unless really_edited?
95
+
115
96
  # TODO: refactor the if condition
116
- 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]
117
98
  # neccessary to recalculate #editor
118
99
  reload
119
- return true
100
+ true
120
101
  end
121
102
 
122
103
  # Creates a working version of the object. Returns true on success or when
@@ -124,41 +105,41 @@ module Reactor
124
105
  # @param comment [String] comment to leave for the next user
125
106
  # 1. user lacks the permissions
126
107
  # 2. other error occured
127
- def edit(comment=nil)
108
+ def edit(comment = nil)
128
109
  edit!(comment)
129
- return true
110
+ true
130
111
  rescue Reactor::Cm::XmlRequestError, Reactor::NotPermitted
131
- return false
112
+ false
132
113
  end
133
114
 
134
115
  # Creates a working version of the object. Returns true on success or when
135
116
  # the object already has a working version. Raises exceptions
136
117
  # @param comment [String] comment to leave for the next user
137
118
  # @raise [Reactor::NotPermitted] current user lacks required permissions
138
- def edit!(comment=nil)
139
- crul_obj.edit!(comment) unless self.really_edited?
119
+ def edit!(comment = nil)
120
+ crul_obj.edit!(comment) unless really_edited?
140
121
  reload
141
- return true
122
+ true
142
123
  end
143
124
 
144
125
  # Returns true, if the object has any links pointing to it.
145
126
  # @raise [Reactor::Cm::XmlRequestError] generic error occoured
146
127
  def has_super_links?
147
- crul_obj.get('hasSuperLinks') == '1'
128
+ crul_obj.get("hasSuperLinks") == "1"
148
129
  end
149
130
 
150
131
  # Return an array of RailsConnector::AbstractObj that contain a link
151
132
  # to this file.
152
133
  # @raise [Reactor::Cm::XmlRequestError] generic error occoured
153
134
  def super_objects
154
- RailsConnector::AbstractObj.where(:obj_id => crul_obj.get('superObjects')).to_a
135
+ RailsConnector::AbstractObj.where(obj_id: crul_obj.get("superObjects")).to_a
155
136
  end
156
137
 
157
138
  # Returns true if this object hasn't been saved yet -- that is, a record
158
139
  # for the object doesn't exist in the data store yet; otherwise, returns false.
159
140
  def new_record?
160
- #!destroyed? && (self.id.nil? || !self.class.exists?(self.id))
161
- !destroyed? && (self.id.nil? || self.path.blank?)
141
+ # !destroyed? && (self.id.nil? || !self.class.exists?(self.id))
142
+ !destroyed? && (id.nil? || path.blank?)
162
143
  end
163
144
 
164
145
  # Stolen from Rails 3.
@@ -192,7 +173,7 @@ module Reactor
192
173
  # Freezes the object.
193
174
  def destroy
194
175
  run_callbacks(:destroy) do
195
- self.delete
176
+ delete
196
177
  end
197
178
  end
198
179
 
@@ -201,12 +182,12 @@ module Reactor
201
182
  # but tries to mimmic their behaviour.
202
183
  def reload(options = nil)
203
184
  RailsConnector::AbstractObj.uncached do
204
- #super # Throws RecordNotFound when changing obj_class
185
+ # super # Throws RecordNotFound when changing obj_class
205
186
  # AR reload
206
187
  clear_aggregation_cache
207
188
  clear_association_cache
208
- fresh_object = RailsConnector::AbstractObj.find(self.id, options)
209
- @attributes = fresh_object.instance_variable_get('@attributes')
189
+ fresh_object = RailsConnector::AbstractObj.find(id, options)
190
+ @attributes = fresh_object.instance_variable_get("@attributes")
210
191
  @attributes_cache = {}
211
192
  # RC reload
212
193
  @attr_values = nil
@@ -227,9 +208,9 @@ module Reactor
227
208
  # 2. generic error occoured
228
209
  def resolve_refs
229
210
  resolve_refs!
230
- return true
211
+ true
231
212
  rescue Reactor::Cm::XmlRequestError, Reactor::NotPermitted
232
- return false
213
+ false
233
214
  end
234
215
 
235
216
  # Resolves references in any of the html fields. Returns true on success,
@@ -237,52 +218,41 @@ module Reactor
237
218
  # @raise [Reactor::NotPermitted] current user lacks required permissions
238
219
  def resolve_refs!
239
220
  crul_obj.resolve_refs!
240
- return true
241
- end
242
-
243
- if Reactor.rails3_0?
244
- # It should excactly match ActiveRecord::Base.new in it's behavior
245
- # @see ActiveRecord::Base.new
246
- def initialize(attributes = nil, &block)
247
- if true || !self.class.send(:attribute_methods_overriden?) # FIXME !!!!
248
- ignored_attributes = ignore_attributes(attributes)
249
- # supress block hijacking!
250
- super(attributes) {}
251
- load_ignored_attributes(ignored_attributes)
252
- yield self if block_given?
253
- else
254
- super(attributes)
255
- end
256
- end
257
- elsif Reactor.rails3_1? || Reactor.rails3_2? || Reactor.rails4_x?
258
- # It should excactly match ActiveRecord::Base.new in it's behavior
259
- # @see ActiveRecord::Base.new
260
- def initialize(attributes = nil, options={}, &block)
261
- if true || !self.class.send(:attribute_methods_overriden?) #FIXME !!!
262
- ignored_attributes = ignore_attributes(attributes)
263
- # supress block hijacking!
264
- super(attributes, options) {}
265
- load_ignored_attributes(ignored_attributes)
266
- yield self if block_given?
267
- else
268
- super(attributes, options)
269
- 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)
270
237
  end
271
- else
272
- raise RuntimeError, "Unsupported Rails version!"
273
238
  end
274
239
 
275
- # Equivalent to Obj#edited?
276
240
  def really_edited?
277
- self.edited?
241
+ # check if really edited with curl request
242
+ crul_obj.edited?
243
+ end
244
+
245
+ def edited_or_committed?
246
+ really_edited? || committed?
278
247
  end
279
248
 
280
249
  # Returns an array of errors
281
250
  def reasons_for_incomplete_state
282
- crul_obj.get('reasonsForIncompleteState') || []
251
+ crul_obj.get("reasonsForIncompleteState") || []
283
252
  end
284
253
 
285
254
  protected
255
+
286
256
  def prevent_resolve_refs
287
257
  @prevent_resolve_refs = true
288
258
  end
@@ -292,12 +262,10 @@ module Reactor
292
262
  end
293
263
 
294
264
  def sanitize_name
295
- return unless self.name.present?
265
+ return unless name.present?
296
266
 
297
- sanitized_name = self.class.send(:sanitize_name, self.name)
298
- if sanitized_name != self.name
299
- self.name = sanitized_name
300
- end
267
+ sanitized_name = self.class.send(:sanitize_name, name)
268
+ self.name = sanitized_name if sanitized_name != name
301
269
  end
302
270
 
303
271
  def crul_attributes_set?
@@ -310,12 +278,12 @@ module Reactor
310
278
 
311
279
  def changed_linklists
312
280
  custom_attrs =
313
- self.singleton_class.send(:instance_variable_get, '@_o_allowed_attrs') ||
314
- self.class.send(:instance_variable_get, '@_o_allowed_attrs') ||
281
+ singleton_class.send(:instance_variable_get, "@_o_allowed_attrs") ||
282
+ self.class.send(:instance_variable_get, "@_o_allowed_attrs") ||
315
283
  []
316
284
 
317
285
  custom_attrs.select do |attr|
318
- self.send(:attribute_type, attr) == :linklist && self.send(:[],attr.to_sym).try(:changed?)
286
+ send(:attribute_type, attr) == :linklist && send(:[], attr.to_sym).try(:changed?)
319
287
  end
320
288
  end
321
289
 
@@ -332,28 +300,27 @@ module Reactor
332
300
  end
333
301
 
334
302
  def crul_obj_save
335
- attrs, _ = crul_attributes.partition do |field, (value, options)|
336
- self.send(:attribute_type, field) != :linklist
303
+ attrs, = crul_attributes.partition do |field, (_value, _options)|
304
+ send(:attribute_type, field) != :linklist
337
305
  end
338
306
  linklists = changed_linklists
339
307
 
340
308
  new_links = {}.tap do |result|
341
309
  linklists.map do |field|
342
310
  result[field] = Reactor::Attributes::LinkListFromAccessor.new(self, field).call.map do |l|
343
- {:link_id => l.id, :title => l.title, :destination_url => (l.internal? ? l.destination_object.path : l.url), :target => l.target}
311
+ { link_id: l.id, title: l.title, destination_url: (l.internal? ? l.destination_object.path : l.url), target: l.target }
344
312
  end
345
313
  end
346
314
  end
347
315
 
348
316
  links_modified = !linklists.empty?
349
317
 
350
- crul_obj.composite_save(attrs, [], [], [], links_modified) do |attrs, links_to_add, links_to_remove, links_to_set|
351
-
318
+ crul_obj.composite_save(attrs, [], [], [], links_modified) do |_attrs, links_to_add, links_to_remove, links_to_set|
352
319
  links_to_add.clear
353
320
  links_to_remove.clear
354
321
  links_to_set.clear
355
322
 
356
- copy = RailsConnector::AbstractObj.uncached { RailsConnector::AbstractObj.find(self.id) }
323
+ copy = RailsConnector::BasicObj.uncached { RailsConnector::BasicObj.find(id) }
357
324
 
358
325
  linklists.each do |linklist|
359
326
  original_link_ids = Reactor::Attributes::LinkListFromAttrValues.new(copy, linklist).call.map(&:id)
@@ -385,7 +352,6 @@ module Reactor
385
352
  end
386
353
  end
387
354
  end
388
-
389
355
  self.class.connection.clear_query_cache
390
356
  end
391
357
 
@@ -398,66 +364,55 @@ module Reactor
398
364
  # @param [String] new_name gives the object new name
399
365
  def copy(new_parent, recursive = false, new_name = nil)
400
366
  self.id = crul_obj.copy(RailsConnector::AbstractObj.path_from_anything(new_parent), recursive, new_name)
401
- #self.reload
402
- resolve_refs #?
403
- self.id
367
+ # self.reload
368
+ resolve_refs # ?
369
+ id
404
370
  end
405
371
 
406
372
  def trim_crul_attributes
407
- crul_attributes.delete_if {|attr, options| [:name, :objClass].include?(attr) }
373
+ crul_attributes.delete_if { |attr, _options| %i(name objClass).include?(attr) }
408
374
  end
409
375
 
410
376
  def crul_obj_create(name, parent, klass)
411
377
  @crul_obj = Reactor::Cm::Obj.create(name, parent, klass)
412
378
  end
413
379
 
380
+ # TODO: depends on rails version
414
381
  def create
415
382
  run_callbacks(:create) do
416
- c_name = self.name
417
- c_parent= self.class.path_from_anything(self.parent_obj_id)
418
- c_objcl = self.obj_class
383
+ c_name = name
384
+ c_parent = self.class.path_from_anything(parent_obj_id)
385
+ c_objcl = obj_class
419
386
  crul_obj_create(c_name, c_parent, c_objcl)
420
387
  self.id = @crul_obj.obj_id
421
388
  crul_obj_save if crul_attributes_set? || crul_links_changed?
422
- self.reload # ?
423
- self.id
389
+ reload # ?
390
+ changes_applied
391
+ id
424
392
  end
425
393
  end
426
394
 
427
- if Reactor.rails4_x?
428
- if Reactor.rails4_0_ge6? || Reactor.rails4_1? || Reactor.rails4_2?
429
- alias_method :_create_record, :create
430
- else
431
- alias_method :create_record, :create
432
- end
433
- end
395
+ alias_method :_create_record, :create
434
396
 
435
- def update
436
- run_callbacks(:update) do
437
- crul_obj_save if crul_attributes_set? || crul_links_changed?
438
- self.reload
439
- self.id
440
- end
441
- end
442
-
443
- if Reactor.rails4_x?
444
- if Reactor.rails4_0_ge6? || Reactor.rails4_1? || Reactor.rails4_2?
445
- alias_method :_update_record, :update
446
- else
447
- alias_method :update_record, :update
397
+ def update(_attribute_names = attribute_names)
398
+ run_callbacks(:update) do
399
+ crul_obj_save if crul_attributes_set? || crul_links_changed?
400
+ reload
401
+ changes_applied
402
+ id
448
403
  end
449
404
  end
450
405
 
406
+ alias_method :_update_record, :update
407
+
451
408
  def ignore_attributes(attributes)
452
409
  return {} if attributes.nil?
453
410
 
454
411
  obj_class = attributes.delete(:obj_class)
455
412
  parent = attributes.delete(:parent)
456
- {:obj_class => obj_class, :parent => parent}
413
+ { obj_class: obj_class, parent: parent }
457
414
  end
458
415
 
459
-
460
-
461
416
  def load_ignored_attributes(attributes)
462
417
  return if attributes.nil?
463
418
 
@@ -475,7 +430,6 @@ module Reactor
475
430
  self.obj_class = obj_class
476
431
  end
477
432
 
478
-
479
433
  # disables active record transactions
480
434
  def with_transaction_returning_status
481
435
  yield
@@ -489,44 +443,17 @@ module Reactor
489
443
  module ClassMethods
490
444
  def sanitize_name(old_name)
491
445
  if Reactor::Configuration.sanitize_obj_name
492
- character_map = {'ä' => 'ae', 'ö' => 'oe', 'ü' => 'ue', 'ß' => 'ss', 'Ä' => 'Ae', 'Ö' => 'Oe', 'Ü' => 'Ue'}
493
- new_name = old_name.gsub(/[^-$a-zA-Z0-9]/) {|char| character_map[char] || '_'}.
494
- gsub(/__+/,'_').
495
- gsub(/^_+/,'').
496
- gsub(/_+$/,'')
497
- new_name
446
+ character_map = { "ä" => "ae", "ö" => "oe", "ü" => "ue", "ß" => "ss", "Ä" => "Ae", "Ö" => "Oe", "Ü" => "Ue" }
447
+ old_name.gsub(/[^-$a-zA-Z0-9]/) { |char| character_map[char] || "_" }
448
+ .gsub(/__+/, "_")
449
+ .gsub(/^_+/, "")
450
+ .gsub(/_+$/, "")
451
+
498
452
  else
499
453
  old_name
500
454
  end
501
455
  end
502
456
 
503
- if Reactor.rails4_x?
504
- # Detect the subclass from the inheritance column of attrs. If the inheritance column value
505
- # is not self or a valid subclass, raises ActiveRecord::SubclassNotFound
506
- # If this is a StrongParameters hash, and access to inheritance_column is not permitted,
507
- # this will ignore the inheritance column and return nil
508
- def subclass_from_attrs(attrs)
509
- subclass_name = attrs.with_indifferent_access[inheritance_column]
510
-
511
- if subclass_name.present? && subclass_name != self.name
512
- subclass = subclass_name.safe_constantize
513
-
514
- if subclass # this if has been added
515
- unless descendants.include?(subclass)
516
- raise ActiveRecord::SubclassNotFound.new("Invalid single-table inheritance type: #{subclass_name} is not a subclass of #{name}")
517
- end
518
-
519
- subclass
520
- end
521
- end
522
- end
523
-
524
- if Reactor.rails4_0_ge6? || Reactor.rails4_1? || Reactor.rails4_2?
525
- alias_method :subclass_from_attributes, :subclass_from_attrs
526
- remove_method :subclass_from_attrs
527
- end
528
- end
529
-
530
457
  # Convenience method: it is equivalent to following call chain:
531
458
  #
532
459
  # i = create(attributes)
@@ -538,22 +465,23 @@ module Reactor
538
465
  #
539
466
  # image = Image.upload(File.open('image.jpg'), 'ext', :name => 'image', :parent => '/')
540
467
  #
541
- def upload(data_or_io, extension, attributes={})
468
+ def upload(data_or_io, extension, attributes = {})
542
469
  # Try to guess the object name from filename, if it's missing
543
- if (data_or_io.respond_to?(:path) && !attributes.key?(:name))
470
+ if data_or_io.respond_to?(:path) && !attributes.key?(:name)
544
471
  attributes[:name] = sanitize_name(File.basename(data_or_io.path, File.extname(data_or_io.path)))
545
472
  end
546
473
 
547
- instance = self.create!(attributes)# do |instance|
548
- instance.upload(data_or_io, extension)
549
- instance.save!
550
- #end
474
+ instance = create!(attributes) # do |instance|
475
+ instance.upload(data_or_io, extension)
476
+ instance.save!
477
+ # end
551
478
  instance
552
479
  end
553
480
 
554
481
  protected
482
+
555
483
  def attribute_methods_overriden?
556
- self.name != 'RailsConnector::AbstractObj'
484
+ name != "RailsConnector::BasicObj"
557
485
  end
558
486
  end
559
487
  end