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,3 +1,2 @@
1
- # -*- encoding : utf-8 -*-
2
1
  Rails.application.routes.draw do
3
2
  end
@@ -1,29 +1,30 @@
1
- # -*- encoding: utf-8 -*-
2
- $:.push File.expand_path("../lib", __FILE__)
1
+ $:.push File.expand_path("lib", __dir__)
3
2
  require "reactor/version"
4
3
 
5
4
  Gem::Specification.new do |s|
6
5
  s.name = "infopark_reactor"
7
- s.version = "#{Reactor::VERSION}"
6
+ s.version = Reactor::VERSION.to_s
8
7
  s.platform = Gem::Platform::RUBY
9
- s.authors = ["Tomasz Przedmojski"]
10
- s.email = ["tomasz.przedmojski@infopark.de"]
8
+ s.authors = ["Tomasz Przedmojski", "Anton Mezin", "Roman Lemekha"]
9
+ s.email = ["tomasz.przedmojski@infopark.de", "anton.mezin@infopark.de", "roman.lemekha@infopark.de"]
11
10
  s.homepage = ""
12
- s.summary = %q{Write into CM in familiar, Rails-like way}
13
- s.description = %q{Use the ActiveRecord mimicking API to write into CM and enjoy all the benefits of callbacks, validations and permission checking}
14
- s.license = 'LGPL-3'
11
+ s.summary = "Write into CM in familiar, Rails-like way"
12
+ s.description = "Use the ActiveRecord mimicking API to write into CM and enjoy all the benefits of callbacks, validations and permission checking"
13
+ s.license = "LGPL-3"
15
14
 
16
- #s.rubyforge_project = "infopark_reactor"
15
+ # s.rubyforge_project = "infopark_reactor"
17
16
 
18
17
  s.files = `git ls-files`.split("\n")
19
18
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
20
- s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
21
20
  s.require_paths = ["lib"]
22
21
 
23
- s.add_dependency 'rails', '>= 3.0.10', '< 4.3.0'
24
- #s.add_dependency 'infopark_rails_connector'
25
- s.add_dependency 'nokogiri'
22
+ s.add_dependency "infopark_fiona_connector", "~> 7.0.1.5.2.3.rc5"
23
+ s.add_dependency "nokogiri"
24
+ s.add_dependency "rails", "~> 5.0"
26
25
 
27
- s.add_development_dependency 'rspec'
28
- s.add_development_dependency 'yard'
26
+ s.add_development_dependency "rspec"
27
+ s.add_development_dependency "rubocop", "~> 0.87.1"
28
+ s.add_development_dependency "rubocop-performance"
29
+ s.add_development_dependency "yard"
29
30
  end
@@ -1,19 +1,15 @@
1
- # -*- encoding : utf-8 -*-
2
1
  module Cm
3
2
  module Generators
4
3
  class MigrationGenerator < Rails::Generators::NamedBase
5
4
  include Rails::Generators::Migration
6
- def self.next_migration_number(dirname)
5
+ def self.next_migration_number(_dirname)
7
6
  Time.now.utc.strftime("%Y%m%d%H%M%S")
8
7
  end
9
8
 
10
- source_root File.expand_path('../templates', __FILE__)
9
+ source_root File.expand_path("templates", __dir__)
10
+
11
11
  def create_migration_file
12
- if Reactor.rails4_x?
13
- migration_template "template.rb", "cm/migrate/#{file_name}.rb"
14
- else
15
- migration_template "template.rb", "cm/migrate/#{file_name}"
16
- end
12
+ migration_template "template.rb", "cm/migrate/#{file_name}.rb"
17
13
  end
18
14
  end
19
15
  end
@@ -1,86 +1,60 @@
1
- # -*- encoding : utf-8 -*-
2
- # Runtime Rails version detection
3
- module Reactor
4
- def self.rails3_0?
5
- ::Rails::VERSION::MAJOR == 3 && ::Rails::VERSION::MINOR == 0
6
- end
7
-
8
- def self.rails3_1?
9
- ::Rails::VERSION::MAJOR == 3 && ::Rails::VERSION::MINOR == 1
10
- end
11
-
12
- def self.rails3_2?
13
- ::Rails::VERSION::MAJOR == 3 && ::Rails::VERSION::MINOR == 2
14
- end
15
-
16
- def self.rails4_0?
17
- ::Rails::VERSION::MAJOR == 4 && ::Rails::VERSION::MINOR == 0
18
- end
19
-
20
- def self.rails4_1?
21
- ::Rails::VERSION::MAJOR == 4 && ::Rails::VERSION::MINOR == 1
22
- end
23
-
24
- def self.rails4_2?
25
- ::Rails::VERSION::MAJOR == 4 && ::Rails::VERSION::MINOR == 2
26
- end
27
-
28
- def self.rails4_x?
29
- ::Rails::VERSION::MAJOR == 4 && [0,1,2].include?(::Rails::VERSION::MINOR)
30
- end
31
-
32
- def self.rails4_0_ge6?
33
- ::Rails::VERSION::MAJOR == 4 && ::Rails::VERSION::MINOR == 0 && ::Rails::VERSION::TINY >= 6
34
- end
35
- end
36
1
  # require config
37
- require 'reactor/configuration'
38
-
2
+ require "reactor/configuration"
39
3
 
40
4
  # require components
41
- require 'reactor/cm/bridge'
42
- require 'reactor/cm/language'
43
- require 'reactor/cm/object_base'
44
- require 'reactor/cm/user'
45
- require 'reactor/cm/attribute'
46
- require 'reactor/cm/obj'
47
- require 'reactor/cm/obj_class'
48
- require 'reactor/cm/attribute_group'
49
- require 'reactor/cm/link'
50
- require 'reactor/cm/group'
51
- require 'reactor/cm/editorial_group'
52
- require 'reactor/cm/live_group'
53
- require 'reactor/cm/workflow'
54
- require 'reactor/cm/log_entry'
55
- require 'reactor/cm/channel'
5
+ require "reactor/cm/bridge"
6
+ require "reactor/cm/language"
7
+ require "reactor/cm/object_base"
8
+ require "reactor/cm/user"
9
+ require "reactor/cm/attribute"
10
+ require "reactor/cm/obj"
11
+ require "reactor/cm/obj_class"
12
+ require "reactor/cm/attribute_group"
13
+ require "reactor/cm/link"
14
+ require "reactor/cm/group"
15
+ require "reactor/cm/editorial_group"
16
+ require "reactor/cm/live_group"
17
+ require "reactor/cm/workflow"
18
+ require "reactor/cm/log_entry"
19
+ require "reactor/cm/channel"
56
20
 
57
21
  # require main class
58
- require 'reactor/migration'
22
+ require "reactor/migration"
59
23
 
60
24
  # require misc
61
- require 'reactor/cm/xml_request_error'
62
- require 'reactor/cm/blob_too_small_error'
63
- require 'reactor/cm/missing_credentials'
25
+ require "reactor/cm/xml_request_error"
26
+ require "reactor/cm/blob_too_small_error"
27
+ require "reactor/cm/missing_credentials"
64
28
 
65
29
  # require public tools
66
- require 'reactor/tools/uploader'
30
+ require "reactor/tools/uploader"
67
31
 
68
32
  # require exceptions
69
- require 'reactor/already_released'
70
- require 'reactor/no_working_version'
71
- require 'reactor/not_permitted'
72
-
73
- # require eager loader
74
- require 'rails_connector/meta/eager_loader'
33
+ require "reactor/already_released"
34
+ require "reactor/no_working_version"
35
+ require "reactor/not_permitted"
75
36
 
76
37
  # require components
77
- require 'reactor/main'
78
- require 'reactor/rc_independent'
79
- require 'reactor/sudo'
38
+ require "reactor/legacy"
39
+ require "reactor/validations"
40
+ require "reactor/permission"
41
+ require "reactor/workflow"
42
+ require "reactor/streaming_upload"
43
+ require "reactor/rc_independent"
44
+ require "reactor/sudo"
45
+ require "reactor/main"
46
+ require "reactor/attributes"
47
+ require "reactor/attributes_handlers"
48
+ require "reactor/persistence"
80
49
 
81
50
  # require rails integration
82
- require 'reactor/session'
83
- require 'reactor/session/user'
51
+ # session handling
52
+ require "reactor/session"
53
+ require "reactor/session/user"
54
+ require "reactor/session_helper/auth_helper"
55
+ require "reactor/session_helper/auth_filter"
56
+ require "reactor/session_helper/rsession_helper"
57
+ require "reactor/session_helper/session_state"
84
58
 
85
59
  # require engine
86
- require File.expand_path('../reactor/engine', __FILE__) if defined?(Rails)
60
+ require File.expand_path("reactor/engine", __dir__) if defined?(Rails)
@@ -1,4 +1,3 @@
1
- # -*- encoding : utf-8 -*-
2
1
  module Reactor
3
- class AlreadyReleased < StandardError ; end
2
+ class AlreadyReleased < StandardError; end
4
3
  end
@@ -1,171 +1,12 @@
1
- # -*- encoding : utf-8 -*-
2
- require 'reactor/attributes/date_serializer'
3
- require 'reactor/attributes/html_serializer'
4
- require 'reactor/attributes/link_list_serializer'
1
+ require "reactor/attributes/date_serializer"
2
+ require "reactor/attributes/html_serializer"
3
+ require "reactor/attributes/link_list_serializer"
5
4
 
6
- require 'reactor/attributes/link_list_extender'
5
+ require "reactor/attributes/link_list_extender"
7
6
 
8
- require 'singleton'
7
+ require "singleton"
9
8
 
10
9
  module Reactor
11
- class AttributeHandlers
12
- include Singleton
13
-
14
- def initialize
15
- # t1 = Time.now
16
- self.generate_attribute_handlers
17
- # Rails.logger.debug "Reactor::AttributeHandlers: generate_attribute_handlers took #{Time.now - t1}"
18
- end
19
-
20
- # Use this method to install attributes into class
21
- def self.install_attributes(klass)
22
- Reactor::AttributeHandlers.instance.install(klass, obj_class(klass))
23
- end
24
-
25
- # Use this method if attributes changed and you wish to reinstall them
26
- def self.reinstall_attributes(klass, obj_class)
27
- Reactor::AttributeHandlers.instance.tap do |handler|
28
- handler.regenerate_attribute_handler(obj_class)
29
- handler.install(klass, obj_class)
30
- end
31
- end
32
-
33
- def self.obj_class(klass)
34
- klass.name.split('::').last
35
- end
36
-
37
- def install(klass, obj_class)
38
- if obj_class_known?(obj_class)
39
- klass.send(:include, handler_module(obj_class))
40
- end
41
- end
42
-
43
- def regenerate_attribute_handler(obj_class_name)
44
- generate_attribute_handler(RailsConnector::Meta::EagerLoader.instance.obj_class(obj_class_name))
45
- end
46
-
47
- protected
48
-
49
- def handler_module(obj_class)
50
- Reactor::AttributeHandlers.const_get('Handler__' + obj_class.to_s)
51
- end
52
-
53
- def obj_class_known?(obj_class)
54
- Reactor::AttributeHandlers.const_defined?('Handler__' + obj_class.to_s)
55
- end
56
-
57
- def generate_attribute_handlers
58
- RailsConnector::Meta::EagerLoader.instance.obj_classes.each do |_, obj_class|
59
- # Rails.logger.debug "Reactor::AttributeHandlers: preparing obj class #{obj_class.name}"
60
- generate_attribute_handler(obj_class) if obj_class.name =~ /^[A-Z]/
61
- end
62
- end
63
-
64
- def generate_attribute_handler(obj_class)
65
- # Rails.logger.debug "Reactor::AttributeHandlers: generating handler for #{obj_class.name}"
66
- attribute_methods = []
67
- writers = []
68
-
69
- obj_class.custom_attributes.each do |attribute, attribute_data|
70
- writers << attribute.to_sym
71
- writers << attribute.to_s.underscore.to_sym
72
-
73
- # Custom attribute readers: prevent unwanted nils
74
- case attribute_data.attribute_type.to_sym
75
- when :html
76
- attribute_methods << <<-EOC
77
- def #{attribute}
78
- self[:#{attribute}] || ''.html_safe
79
- end
80
- EOC
81
- when :date, :enum
82
- attribute_methods << <<-EOC
83
- def #{attribute}
84
- self[:#{attribute}]
85
- end
86
- EOC
87
- when :linklist
88
- attribute_methods << <<-EOC
89
- def #{attribute}
90
- self[:#{attribute}] || RailsConnector::LinkList.new([])
91
- end
92
- EOC
93
- when :multienum
94
- attribute_methods << <<-EOC
95
- def #{attribute}
96
- self[:#{attribute}] || []
97
- end
98
- EOC
99
- else
100
- attribute_methods << <<-EOC
101
- def #{attribute}
102
- self[:#{attribute}] || ''
103
- end
104
- EOC
105
- end
106
-
107
- # active model dirty tracking
108
- attribute_methods << <<-EOC
109
- def #{attribute}_changed?
110
- attribute_changed?(:#{attribute})
111
- end
112
- EOC
113
- end
114
-
115
-
116
-
117
- [:contentType].each do |attribute|
118
- writers << attribute.to_sym
119
- writers << attribute.to_s.underscore.to_sym
120
- end
121
-
122
- Reactor::Cm::Obj::OBJ_ATTRS.each do |attribute|
123
- writers << attribute.to_sym
124
- writers << attribute.to_s.underscore.to_sym
125
- end
126
-
127
- writers.uniq!
128
-
129
- writers.each do |attribute|
130
- attribute_methods << <<-EOC
131
- def #{attribute}=(value)
132
- set(:#{attribute},value)
133
- end
134
- EOC
135
- end
136
-
137
- # if a handler for this obj class has been defined previously, purge its methods
138
- if Reactor::AttributeHandlers.const_defined?("Handler__#{obj_class.name}")
139
- mod = Reactor::AttributeHandlers.const_get("Handler__#{obj_class.name}")
140
- mod.instance_methods.each do |method|
141
- mod.send(:remove_method, method)
142
- end
143
- end
144
-
145
- Reactor.class_eval <<-EOC
146
- class AttributeHandlers
147
- module Handler__#{obj_class.name}
148
- def self.included(base)
149
- # store allowed attributes
150
- allowed_attrs = %w|#{writers * ' '}|.map(&:to_sym)
151
- base.send(:instance_variable_set, '@_o_allowed_attrs', allowed_attrs)
152
- end
153
-
154
- # attribute readers and writers
155
- #{attribute_methods.join("\n")}
156
-
157
- # parent-setting handling
158
- def parent=(parent_something)
159
- set_parent(parent_something)
160
- end
161
- end
162
- end
163
- EOC
164
-
165
- handler_module(obj_class.name)
166
- # "Reactor::AttributeHandlers::Handler__#{obj_class.name}"
167
- end
168
- end
169
10
  # This module provides support for ActiveRecord like attribute setting, plus additional
170
11
  # #set method, which is equivalent to the setters.
171
12
  #
@@ -197,7 +38,7 @@ module Reactor
197
38
  def permalink=(value)
198
39
  set(:permalink, value)
199
40
  end
200
-
41
+
201
42
  def name=(value)
202
43
  set(:name, value)
203
44
  end
@@ -207,11 +48,7 @@ module Reactor
207
48
  end
208
49
 
209
50
  def blob
210
- if attr_dict.respond_to?(:blob)
211
- attr_dict.send :blob
212
- else
213
- nil
214
- end
51
+ attr_dict.send :blob if attr_dict.respond_to?(:blob)
215
52
  end
216
53
 
217
54
  def blob=(value)
@@ -226,49 +63,46 @@ module Reactor
226
63
  set(:channels, value)
227
64
  end
228
65
 
229
- def suppress_export=(value)
230
- set(:suppress_export, value)
231
- end
232
-
233
66
  def channels
234
67
  self[:channels] || []
235
68
  end
236
69
 
237
- def body_changed?
238
- attribute_changed?(:body)
239
- end
240
-
241
- def title_changed?
242
- attribute_changed?(:title)
70
+ def suppress_export=(value)
71
+ set(:suppress_export, value)
243
72
  end
244
73
 
245
- def channels_changed?
246
- attribute_changed?(:channels)
74
+ def _read_attribute(key)
75
+ if active_record_attr?(key)
76
+ super
77
+ else
78
+ __send__(key)
79
+ end
247
80
  end
248
81
 
249
82
  # Sets given attribute, to given value. Converts values if neccessary
250
83
  # @see [Reactor::Attributes]
251
84
  # @note options are passed to underlying xml interface, but as of now have no effect
252
- def set(key, value, options={})
85
+ def set(key, value, options = {})
253
86
  key = key.to_sym
254
87
  raise TypeError, "can't modify frozen object" if frozen?
255
- key = resolve_attribute_alias(key)
256
- raise ArgumentError, "Unknown attribute #{key.to_s} for #{self.class.to_s} #{self.path}" unless allowed_attr?(key)
257
- attr = key_to_attr(key)
88
+ raise ArgumentError, "Unknown attribute #{key} for #{self.class} #{path}" unless allowed_attr?(key)
258
89
 
259
- not_formated_value = value
260
- formated_value = serialize_value(key, value)
261
- crul_set(attr, formated_value, options)
90
+ attribute_will_change!(key.to_s)
262
91
 
263
- __track_dirty_attribute(key)
264
- active_record_set(key, formated_value) if active_record_attr?(key)
265
- rails_connector_set(key, formated_value, not_formated_value)
92
+ attribute = key_to_attr(key)
266
93
 
267
- # return new value
94
+ formated_value = serialize_value(key, value)
95
+ crul_set(attribute, formated_value, options)
96
+
97
+ if active_record_attr?(key)
98
+ formated_value = to_time_in_zone(formated_value) if attribute_type(key) == :date
99
+ else
100
+ rails_connector_set(key, formated_value)
101
+ end
102
+ @attributes.write_from_user(key.to_s, formated_value)
268
103
  __send__(key)
269
104
  end
270
105
 
271
-
272
106
  # Uploads a file/string into a CM. Requires call to save afterwards(!)
273
107
  # @param [String, IO] data_or_io
274
108
  # @param [String] extension file extension
@@ -279,16 +113,16 @@ module Reactor
279
113
  end
280
114
 
281
115
  def uploaded?
282
- self.uploaded == true
116
+ uploaded == true
283
117
  end
284
118
 
285
119
  # @deprecated
286
120
  def set_link(key, id_or_path_or_cms_obj)
287
121
  target_path = case id_or_path_or_cms_obj
288
- when Fixnum then Obj.find(id_or_path_or_cms_obj).path
289
- when String then id_or_path_or_cms_obj
290
- when Obj then id_or_path_or_cms_obj.path
291
- else raise ArgumentError.new("Link target must Fixnum, String or Obj, but was #{id_or_path_or_cms_obj.class}.")
122
+ when Integer then Obj.find(id_or_path_or_cms_obj).path
123
+ when String then id_or_path_or_cms_obj
124
+ when Obj then id_or_path_or_cms_obj.path
125
+ else raise ArgumentError, "Link target must Integer, String or Obj, but was #{id_or_path_or_cms_obj.class}."
292
126
  end
293
127
 
294
128
  edit!
@@ -296,45 +130,53 @@ module Reactor
296
130
  crul_obj.set_link(key, target_path.to_s)
297
131
  end
298
132
 
299
- def reload_attributes(new_obj_class=nil)
300
- new_obj_class = new_obj_class || self.obj_class
133
+ def reload_attributes(new_obj_class = nil)
134
+ new_obj_class ||= obj_class
301
135
  RailsConnector::Meta::EagerLoader.instance.forget_obj_class(new_obj_class)
302
- Reactor::AttributeHandlers.reinstall_attributes(self.singleton_class, new_obj_class)
136
+ Reactor::AttributeHandlers.reinstall_attributes(singleton_class, new_obj_class)
137
+ self.class.initialize_attributes
303
138
  end
304
139
 
305
140
  protected
141
+
306
142
  attr_accessor :uploaded
143
+
144
+ def builtin_attributes
145
+ @builtin_attrs ||= (active_record_attributes + Reactor::Cm::Obj::PREDEFINED_ATTRS).map { |item| item.to_s.underscore.to_sym }
146
+ end
147
+
307
148
  def builtin_attr?(attr)
308
- [:channels, :parent, :valid_from, :valid_until, :name, :obj_class, :content_type, :body, :blob, :suppress_export, :permalink, :title].include?(attr)
149
+ builtin_attributes.include?(attr)
150
+ end
151
+
152
+ def active_record_attributes
153
+ @active_record_attrs ||= self.class.columns.map(&:name)
309
154
  end
310
155
 
311
156
  def active_record_attr?(attr)
312
- [:valid_from, :valid_until, :name, :obj_class, :suppress_export, :permalink].include?(attr)
157
+ active_record_attributes.include?(attr.to_s)
313
158
  end
314
159
 
315
160
  def allowed_attr?(attr)
161
+ # TODO: rebuild with current attribute_names method
316
162
  return true if builtin_attr?(attr)
317
163
 
318
- custom_attrs =
319
- self.singleton_class.send(:instance_variable_get, '@_o_allowed_attrs') ||
320
- self.class.send(:instance_variable_get, '@_o_allowed_attrs') ||
164
+ custom_attrs =
165
+ singleton_class.send(:instance_variable_get, "@_o_allowed_attrs") ||
166
+ self.class.send(:instance_variable_get, "@_o_allowed_attrs") ||
321
167
  []
322
168
 
323
169
  custom_attrs.include?(key_to_attr(attr))
324
170
  end
325
171
 
326
- def resolve_attribute_alias(key)
327
- key
328
- end
329
-
330
172
  def key_to_attr(key)
331
173
  @__attribute_map ||= {
332
- :body => :blob,
333
- :valid_until => :validUntil,
334
- :valid_from => :validFrom,
335
- :content_type => :contentType,
336
- :suppress_export => :suppressExport,
337
- :obj_class => :objClass
174
+ body: :blob,
175
+ valid_until: :validUntil,
176
+ valid_from: :validFrom,
177
+ content_type: :contentType,
178
+ suppress_export: :suppressExport,
179
+ obj_class: :objClass
338
180
  }
339
181
 
340
182
  key = key.to_sym
@@ -342,67 +184,43 @@ module Reactor
342
184
  key
343
185
  end
344
186
 
345
- def serialize_value(attr, value)
346
- case attribute_type(attr)
187
+ def serialize_value(key, value)
188
+ case attribute_type(key)
347
189
  when :html
348
- HTMLSerializer.new(attr, value).serialize
190
+ HTMLSerializer.new(key, value).serialize
349
191
  when :date
350
- DateSerializer.new(attr, value).serialize
192
+ DateSerializer.new(key, value).serialize
351
193
  when :linklist
352
- LinkListSerializer.new(attr, value).serialize
194
+ LinkListSerializer.new(key, value).serialize
353
195
  else
354
196
  value
355
197
  end
356
198
  end
357
199
 
358
- def rails_connector_set(field, value, supplied_value)
359
- field = :blob if field.to_sym == :body
200
+ def rails_connector_set(field, value)
360
201
  field = field.to_sym
361
-
202
+ field = :blob if field == :body
362
203
  case attribute_type(field)
363
204
  when :linklist
364
- send(:attr_dict).instance_variable_get('@attr_cache')[field] = value
205
+ send(:attr_dict).instance_variable_get("@attr_cache")[field] = value
365
206
  send(:attr_dict).send(:blob_dict)[field] = :special_linklist_handling_is_broken
366
207
  when :date
367
- if supplied_value.nil? || supplied_value.kind_of?(String)
368
- parsed_value = Time.from_iso(value).in_time_zone rescue nil
369
- else
370
- parsed_value = supplied_value
371
- end
372
- send(:attr_dict).instance_variable_get('@attr_cache')[field] = parsed_value
208
+ send(:attr_dict).instance_variable_get("@attr_cache")[field] = to_time_in_zone(value)
373
209
  send(:attr_dict).send(:blob_dict)[field] = value
374
210
  else
375
- send(:attr_dict).instance_variable_get('@attr_cache')[field] = nil
211
+ send(:attr_dict).instance_variable_get("@attr_cache")[field] = nil
376
212
  send(:attr_dict).send(:blob_dict)[field] = value
377
213
  end
378
214
  end
379
215
 
380
- def cached_value?(attr, value)
381
- attribute_type(attr) == :linklist
382
- end
216
+ def to_time_in_zone(value)
217
+ return nil if value.blank?
383
218
 
384
- if Reactor.rails4_2?
385
- def active_record_set(field, value)
386
- @attributes.write_from_user(field.to_s, value)
387
- end
388
- else
389
- def active_record_set(field, value)
390
- @attributes_cache.delete(field.to_s)
391
- @attributes[field.to_s] = value
392
- end
219
+ ActiveSupport::TimeZone["UTC"].parse(value).in_time_zone
393
220
  end
394
221
 
395
- if Reactor.rails4_2? || Reactor.rails4_1?
396
- def __track_dirty_attribute(key)
397
- __send__(:attribute_will_change!, key.to_s)
398
- end
399
- else
400
- def __track_dirty_attribute(key)
401
- # in rails versions <= Rails 4.0 sometimes the first option
402
- # and sometimes the second option is used
403
- __send__(:attribute_will_change!, key.to_s)
404
- __send__(:attribute_will_change!, key.to_sym)
405
- end
222
+ def cached_value?(attr, _value)
223
+ attribute_type(attr) == :linklist
406
224
  end
407
225
 
408
226
  # Lazily sets values for crul interface. May be removed in later versions
@@ -412,21 +230,24 @@ module Reactor
412
230
  end
413
231
 
414
232
  private
415
- def path=(*args) ; super ; end
233
+
234
+ def path=(*args)
235
+ super
236
+ end
416
237
 
417
238
  def attribute_type(attr)
418
- return :html if [:body, :blob].include?(attr.to_sym)
419
- return :date if [:valid_from, :valid_until, :last_changed].include?(attr.to_sym)
420
- return :string if [:name, :title, :obj_class, :permalink, :suppress_export].include?(attr.to_sym)
239
+ return :html if %i(body blob).include?(attr.to_sym)
240
+ return :date if %i(valid_from valid_until last_changed).include?(attr.to_sym)
241
+ return :string if %i(name title obj_class permalink suppress_export).include?(attr.to_sym)
421
242
  return :multienum if [:channels].include?(attr.to_sym)
422
243
 
423
- custom_attr = self.obj_class_def.try(:custom_attributes).try(:[],attr.to_s)
424
- raise TypeError, "obj_class_def is nil for: #{obj_class}" if self.obj_class_def.nil?
244
+ custom_attr = obj_class_def.try(:custom_attributes).try(:[], attr.to_s)
245
+ raise TypeError, "obj_class_def is nil for: #{obj_class}" if obj_class_def.nil?
425
246
 
426
247
  # FIXME: this should blow up on error
427
248
  # raise TypeError, "Unable to determine type of attribute: #{attr}" if custom_attr.nil?
428
- custom_attr ||= {"attribute_type"=>:string}
429
- return custom_attr["attribute_type"].to_sym
249
+ custom_attr ||= { "attribute_type" => :string }
250
+ custom_attr["attribute_type"].to_sym
430
251
  end
431
252
  end
432
253
  module ClassMethods
@@ -440,21 +261,24 @@ module Reactor
440
261
  end
441
262
 
442
263
  def __cms_attributes(obj_class)
443
- obj_class_def = RailsConnector::Meta::EagerLoader.instance.obj_class(obj_class) #RailsConnector::ObjClass.where(:obj_class_name => obj_class).first
264
+ obj_class_def = RailsConnector::Meta::EagerLoader.instance.obj_class(obj_class) # RailsConnector::ObjClass.where(:obj_class_name => obj_class).first
444
265
  obj_class_def ? obj_class_def.custom_attributes : {}
445
266
  end
446
267
 
447
268
  def __mandatory_cms_attributes(obj_class)
448
- obj_class_def = RailsConnector::Meta::EagerLoader.instance.obj_class(obj_class) #RailsConnector::ObjClass.where(:obj_class_name => obj_class).first
449
- obj_class_def ? obj_class_def.mandatory_attribute_names(:only_custom_attributes => true) : []
269
+ obj_class_def = RailsConnector::Meta::EagerLoader.instance.obj_class(obj_class) # RailsConnector::ObjClass.where(:obj_class_name => obj_class).first
270
+ obj_class_def ? obj_class_def.mandatory_attribute_names(only_custom_attributes: true) : []
450
271
  end
451
272
 
452
- def reload_attributes(new_obj_class=nil)
453
- new_obj_class ||= self.name
454
- raise ArgumentError, "Cannot reload attributes because obj_class is unknown, provide one as a parameter" if new_obj_class.nil?
273
+ def reload_attributes(new_obj_class = nil)
274
+ new_obj_class ||= name
275
+ if new_obj_class.nil?
276
+ raise ArgumentError, "Cannot reload attributes because obj_class is unknown, provide one as a parameter"
277
+ end
455
278
 
456
279
  RailsConnector::Meta::EagerLoader.instance.forget_obj_class(new_obj_class)
457
280
  Reactor::AttributeHandlers.reinstall_attributes(self, new_obj_class)
281
+ initialize_attributes
458
282
  end
459
283
  end
460
284
  end