infopark_fiona_connector 7.0.1.5.2.3.rc4 → 7.0.1.5.2.4.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/cms_controller.rb +1 -1
  3. data/app/controllers/rails_connector/default_cms_controller.rb +0 -2
  4. data/app/helpers/cms_helper.rb +1 -1
  5. data/app/helpers/cms_routing_helper.rb +1 -1
  6. data/app/helpers/rails_connector/cms_asset_helper.rb +4 -5
  7. data/app/helpers/rails_connector/cms_tag_helper.rb +0 -3
  8. data/app/helpers/rails_connector/default_cms_helper.rb +0 -2
  9. data/app/helpers/rails_connector/default_cms_routing_helper.rb +15 -16
  10. data/app/helpers/rails_connector/display_helper.rb +31 -33
  11. data/app/helpers/rails_connector/editing_helper.rb +2 -8
  12. data/app/helpers/rails_connector/layout_helper.rb +2 -5
  13. data/app/helpers/rails_connector/marker_helper.rb +63 -64
  14. data/app/helpers/rails_connector/table_of_contents_helper.rb +1 -3
  15. data/config/cms_routes.rb +15 -15
  16. data/lib/gem_dependencies.rb +8 -7
  17. data/lib/generators/rails_connector/install/install_generator.rb +6 -6
  18. data/lib/generators/rails_connector/install/templates/initializers/rails_connector.rb +1 -1
  19. data/lib/infopark_fiona_connector.rb +9 -9
  20. data/lib/rails_connector/attr_dict.rb +27 -19
  21. data/lib/rails_connector/attribute.rb +18 -21
  22. data/lib/rails_connector/authenticable.rb +12 -5
  23. data/lib/rails_connector/basic_obj.rb +69 -57
  24. data/lib/rails_connector/blob.rb +2 -5
  25. data/lib/rails_connector/blob_mapping.rb +2 -3
  26. data/lib/rails_connector/blob_mysql.rb +3 -5
  27. data/lib/rails_connector/blob_oracle.rb +5 -7
  28. data/lib/rails_connector/channel.rb +5 -6
  29. data/lib/rails_connector/cms_accessible.rb +16 -17
  30. data/lib/rails_connector/cms_base_model.rb +12 -4
  31. data/lib/rails_connector/cms_dispatch_controller.rb +3 -6
  32. data/lib/rails_connector/cms_env.rb +4 -7
  33. data/lib/rails_connector/cms_test_request.rb +1 -1
  34. data/lib/rails_connector/configuration.rb +12 -16
  35. data/lib/rails_connector/content.rb +0 -4
  36. data/lib/rails_connector/core_extensions/time.rb +3 -4
  37. data/lib/rails_connector/date_attribute.rb +1 -3
  38. data/lib/rails_connector/default_search_request.rb +1 -1
  39. data/lib/rails_connector/engine.rb +18 -21
  40. data/lib/rails_connector/errors.rb +2 -5
  41. data/lib/rails_connector/fiona_datetime.rb +2 -2
  42. data/lib/rails_connector/fiona_engine.rb +3 -4
  43. data/lib/rails_connector/html_string.rb +0 -2
  44. data/lib/rails_connector/job.rb +0 -3
  45. data/lib/rails_connector/link.rb +7 -4
  46. data/lib/rails_connector/link_list.rb +1 -5
  47. data/lib/rails_connector/link_resolvable.rb +1 -5
  48. data/lib/rails_connector/lucene_search_request.rb +20 -24
  49. data/lib/rails_connector/markdown_string.rb +0 -2
  50. data/lib/rails_connector/meta.rb +29 -30
  51. data/lib/rails_connector/meta/eager_loader.rb +14 -12
  52. data/lib/rails_connector/named_link.rb +12 -16
  53. data/lib/rails_connector/news.rb +3 -3
  54. data/lib/rails_connector/obj_class.rb +23 -25
  55. data/lib/rails_connector/obj_class_attr.rb +1 -1
  56. data/lib/rails_connector/object_with_meta_data.rb +0 -5
  57. data/lib/rails_connector/permission.rb +2 -6
  58. data/lib/rails_connector/ses.rb +3 -8
  59. data/lib/rails_connector/ses/verity_accessor.rb +43 -46
  60. data/lib/rails_connector/string_tagging.rb +0 -3
  61. data/lib/rails_connector/verity_search_request.rb +6 -9
  62. data/lib/search_request.rb +1 -1
  63. data/lib/version.rb +1 -1
  64. metadata +2 -2
@@ -1,11 +1,9 @@
1
1
  module RailsConnector
2
-
3
2
  #
4
3
  # This module contains a helper that can be used to build a table of contents of an object.
5
4
  #
6
5
  # @api public
7
6
  module TableOfContentsHelper
8
-
9
7
  #
10
8
  # The <tt>table_of_contents</tt> helper method gets an object as argument and returns an array,
11
9
  # which can be used as the table of contents of the given object.
@@ -16,7 +14,7 @@ module RailsConnector
16
14
  #
17
15
  # @api public
18
16
  def table_of_contents(obj)
19
- obj.sorted_toclist.reject { |o| not o.permitted_for_user?(current_user) }
17
+ obj.sorted_toclist.reject { |o| !o.permitted_for_user?(current_user) }
20
18
  end
21
19
  end
22
20
  end
@@ -1,17 +1,17 @@
1
1
  Rails.application.routes.draw do
2
- root to: 'rails_connector/cms_dispatch#index'
3
- match ':id(/*slug)',
4
- to: 'rails_connector/cms_dispatch#index',
5
- constraints: { id: /\d+|[0-9a-f]{16}/ },
6
- as: "cms_id",
7
- via: :all
8
- match 'toggle_markers/:id',
9
- to: 'rails_connector/cms_dispatch#toggle_editmarkers',
10
- as: "toggle_markers",
11
- via: :all
12
- match '/*permalink',
13
- to: 'rails_connector/cms_dispatch#index',
14
- as: 'cms_permalink',
15
- format: false,
16
- via: :all
2
+ root to: "rails_connector/cms_dispatch#index"
3
+ match ":id(/*slug)",
4
+ to: "rails_connector/cms_dispatch#index",
5
+ constraints: { id: /\d+|[0-9a-f]{16}/ },
6
+ as: "cms_id",
7
+ via: :all
8
+ match "toggle_markers/:id",
9
+ to: "rails_connector/cms_dispatch#toggle_editmarkers",
10
+ as: "toggle_markers",
11
+ via: :all
12
+ match "/*permalink",
13
+ to: "rails_connector/cms_dispatch#index",
14
+ as: "cms_permalink",
15
+ format: false,
16
+ via: :all
17
17
  end
@@ -1,6 +1,6 @@
1
1
  class GemDependencies
2
2
  def self.dependency_for(gem_name)
3
- dependencies.detect{ |dep| dep[:name] == gem_name }
3
+ dependencies.detect { |dep| dep[:name] == gem_name }
4
4
  end
5
5
 
6
6
  # generates code that should be included or eval'ed inside a Gemfile.
@@ -14,7 +14,7 @@ class GemDependencies
14
14
  dependencies_minimum_versions = dependencies.map do |dependency|
15
15
  minimum_version = calculate_minimum_version(dependency[:version])
16
16
  if minimum_version
17
- dependency.merge(:version => "= #{minimum_version}")
17
+ dependency.merge(version: "= #{minimum_version}")
18
18
  else
19
19
  dependency.delete(:version)
20
20
  end
@@ -23,7 +23,8 @@ class GemDependencies
23
23
 
24
24
  dependencies_minimum_versions.map do |dependency|
25
25
  gem_name = dependency[:name]
26
- next if gem_name == 'rails'
26
+ next if gem_name == "rails"
27
+
27
28
  gem_options = ""
28
29
  gem_options << ", '#{dependency[:version]}'" if dependency[:version]
29
30
  gem_options <<
@@ -41,11 +42,11 @@ class GemDependencies
41
42
  end.join("\n")
42
43
  end
43
44
 
44
- def self.minimum_version_for(gem, version=nil)
45
- version ||= dependencies.select do |dep|
45
+ def self.minimum_version_for(gem, version = nil)
46
+ dependency ||= dependencies.detect do |dep|
46
47
  dep[:name] == gem
47
- end.first[:version]
48
-
48
+ end
49
+ version ||= dependency[:version]
49
50
  calculate_minimum_version(version)
50
51
  end
51
52
 
@@ -6,19 +6,19 @@ module RailsConnector
6
6
  # Normally, you'd just call 'source_root' as a class method from here,
7
7
  # but we need to glob the dir ourselves. Hence our own method.
8
8
  def self.source_root
9
- @source_root ||= File.expand_path('../templates', __FILE__)
9
+ @source_root ||= File.expand_path("templates", __dir__)
10
10
  end
11
11
 
12
12
  def install_configuration
13
13
  copy_file "initializers/rails_connector.rb", "config/initializers/rails_connector.rb"
14
- template 'app/models/obj.rb.erb', 'app/models/obj.rb'
14
+ template "app/models/obj.rb.erb", "app/models/obj.rb"
15
15
  copy_file "local/configuration.rb", "config/local/configuration.rb"
16
16
  end
17
17
 
18
18
  def append_asset_manifests
19
19
  append_file("app/assets/javascripts/application.js", "//= require infopark_rails_connector")
20
20
  gsub_file("app/assets/stylesheets/application.css", "*= require_tree .",
21
- "*= require_tree .\n *= require infopark_rails_connector")
21
+ "*= require_tree .\n *= require infopark_rails_connector")
22
22
  end
23
23
 
24
24
  def remove_public_index_html
@@ -28,10 +28,10 @@ module RailsConnector
28
28
 
29
29
  def patch_default_application_layout
30
30
  gsub_file("app/views/layouts/application.html.erb", %r{</head>},
31
- "<%= rails_connector_header_tags %>\n</head>")
31
+ "<%= rails_connector_header_tags %>\n</head>")
32
32
  gsub_file("app/views/layouts/application.html.erb", %r{</body>},
33
- "<%= rails_connector_after_content_tags %>\n</body>")
33
+ "<%= rails_connector_after_content_tags %>\n</body>")
34
34
  end
35
35
  end
36
36
  end
37
- end
37
+ end
@@ -1,2 +1,2 @@
1
1
  # Name of the CMS Fiona Instance to access
2
- RailsConnector::Configuration.instance_name = 'default'
2
+ RailsConnector::Configuration.instance_name = "default"
@@ -1,7 +1,7 @@
1
1
  # @api public
2
2
  module ::RailsConnector
3
- PLATFORM_CLOUD = :cloud.freeze
4
- PLATFORM_FIONA = :fiona.freeze
3
+ PLATFORM_CLOUD = :cloud
4
+ PLATFORM_FIONA = :fiona
5
5
 
6
6
  # return either <tt>:fiona</tt> or <tt>:cloud</tt> depending on the app's configuration.
7
7
  # @return [Symbol]
@@ -18,16 +18,16 @@ module ::RailsConnector
18
18
  end
19
19
  end
20
20
 
21
- require 'rails_connector/core_extensions'
22
- require 'rails_connector/rack_middlewares'
23
- require 'rails_connector/errors'
24
- require 'rails_connector/fiona_datetime'
21
+ require "rails_connector/core_extensions"
22
+ require "rails_connector/rack_middlewares"
23
+ require "rails_connector/errors"
24
+ require "rails_connector/fiona_datetime"
25
25
  ActiveRecord::Type.register(:fiona_datetime, ::FionaDateTime)
26
26
 
27
27
  # @api public
28
28
  module RailsConnector
29
29
  def self.autoload_all_sources
30
- source_files = Dir.glob(File.expand_path("../rails_connector/*.rb", __FILE__)).map do |file|
30
+ source_files = Dir.glob(File.expand_path("rails_connector/*.rb", __dir__)).map do |file|
31
31
  File.basename(file)
32
32
  end
33
33
 
@@ -40,5 +40,5 @@ module RailsConnector
40
40
  autoload_all_sources
41
41
  end
42
42
 
43
- require 'rails_connector/engine' if defined?(Rails)
44
- require 'rails_connector/fiona_engine' if defined?(Rails)
43
+ require "rails_connector/engine" if defined?(Rails)
44
+ require "rails_connector/fiona_engine" if defined?(Rails)
@@ -1,15 +1,13 @@
1
- require 'mime/types'
2
- require 'ostruct'
1
+ require "mime/types"
2
+ require "ostruct"
3
3
 
4
4
  module RailsConnector
5
-
6
5
  # The page related and custom data belonging to a CMS object
7
6
  #
8
7
  # [editor] The login of the current editor of the edited content, if set
9
8
  #
10
9
  # Any custom Attribute can be accessed directly or via [].
11
10
  class AttrDict
12
-
13
11
  def initialize(object, keys_and_values = {}, defs = {})
14
12
  @object = object
15
13
  @blob_dict = keys_and_values.symbolize_keys
@@ -34,7 +32,7 @@ module RailsConnector
34
32
  # The body attribute may contain binary data for Obj.binary? or be an HtmlString.
35
33
  def body
36
34
  if object.binary?
37
- binary_body.data if binary_body
35
+ binary_body&.data
38
36
  else
39
37
  StringTagging.tag_as_html(textual_body, self)
40
38
  end
@@ -54,7 +52,8 @@ module RailsConnector
54
52
  def body_data_path
55
53
  # TODO: Braucht/will jemand Text gestreamt?
56
54
  return nil unless object.binary?
57
- binary_body.path_of_stored_data(object.last_changed) if binary_body
55
+
56
+ binary_body&.path_of_stored_data(object.last_changed)
58
57
  end
59
58
 
60
59
  def [](key)
@@ -68,10 +67,10 @@ module RailsConnector
68
67
  end
69
68
 
70
69
  def permissions
71
- @permissions ||= OpenStruct.new({ :live => permitted_groups })
70
+ @permissions ||= OpenStruct.new({ live: permitted_groups })
72
71
  end
73
72
 
74
- def respond_to?(method_id, include_private=false)
73
+ def respond_to?(method_id, include_private = false)
75
74
  super || has_attribute(method_id)
76
75
  end
77
76
 
@@ -83,29 +82,33 @@ module RailsConnector
83
82
 
84
83
  def textual_body
85
84
  return nil if object.binary?
85
+
86
86
  blob_dict[:blob]
87
87
  end
88
88
 
89
89
  def binary_body
90
90
  return nil unless object.binary? && has_attribute(:blob)
91
+
91
92
  @binary_body ||= Blob.find(blob)
92
93
  rescue RailsConnector::ResourceNotFound
93
94
  nil
94
95
  end
95
96
 
96
97
  def method_missing(method_id, *args)
97
- raise NoMethodError.new("missing method - #{method_id}") unless args.empty?
98
- return attribute_value(method_id.to_s)
98
+ raise NoMethodError, "missing method - #{method_id}" unless args.empty?
99
+
100
+ attribute_value(method_id.to_s)
99
101
  rescue UnknownAttributeError
100
- raise NoMethodError.new("missing method - #{method_id}")
102
+ raise NoMethodError, "missing method - #{method_id}"
101
103
  end
102
104
 
103
105
  def attribute_value(key)
104
- raise UnknownAttributeError.new unless has_attribute(key)
106
+ raise UnknownAttributeError unless has_attribute(key)
105
107
 
106
108
  key = key.to_sym
107
109
  raw = blob_dict[key]
108
- @attr_cache[key] ||= case type_of(key)
110
+ @attr_cache[key] ||=
111
+ case type_of(key)
109
112
  when :markdown
110
113
  StringTagging.tag_as_markdown(raw, self)
111
114
  when :html
@@ -120,18 +123,19 @@ module RailsConnector
120
123
  raw || []
121
124
  else
122
125
  raw
123
- end
126
+ end
124
127
  end
125
128
 
126
129
  # this attributes are defined by cms
127
130
  # but if not set, are not existend in attr_defs
128
131
  def predefined_attribute?(key)
129
- [:channels, :sort_key1, :sort_key2, :sort_key3].include?(key.to_sym)
132
+ %i(channels sort_key1 sort_key2 sort_key3).include?(key.to_sym)
130
133
  end
131
134
 
132
135
  def has_attribute(key)
133
136
  key = key.to_sym
134
- return true if predefined_attribute?(key)
137
+ return true if object.class::PREDEFINED_ATTRIBUTES.include?(key.to_s)
138
+
135
139
  blob_dict.key?(key) || attr_defs.key?(key) || class_defined_attributes.key?(key)
136
140
  end
137
141
 
@@ -139,15 +143,20 @@ module RailsConnector
139
143
  key = key.to_sym
140
144
  return :linklist if key == :text_links
141
145
  return :multienum if key == :channels
146
+
142
147
  type_from_attr_defs(key) || type_from_class_defined_attributes(key)
143
148
  end
144
149
 
145
150
  def type_from_attr_defs(key)
146
- attr_defs[key]['type'].to_sym rescue nil
151
+ attr_defs[key]["type"].to_sym
152
+ rescue StandardError
153
+ nil
147
154
  end
148
155
 
149
156
  def type_from_class_defined_attributes(key)
150
- class_defined_attributes[key].type.to_sym rescue nil
157
+ class_defined_attributes[key].type.to_sym
158
+ rescue StandardError
159
+ nil
151
160
  end
152
161
 
153
162
  def class_defined_attributes
@@ -157,5 +166,4 @@ module RailsConnector
157
166
 
158
167
  class UnknownAttributeError < StandardError
159
168
  end
160
-
161
169
  end
@@ -1,18 +1,16 @@
1
1
  module RailsConnector
2
-
3
2
  # The methods date?, enum?, html?, linklist?, markdown?, multienum?, string? and
4
3
  # text? are created by meta programming have no documentation of their own.
5
4
  # Warning: Dependent on the setup of your DB replication, most tables
6
5
  # with meta information will not be available on your live system!
7
6
  class Attribute < CmsBaseModel
8
-
9
7
  # The possible types of an attribute.
10
- TYPES = %w{date enum html linklist markdown multienum string text}
8
+ TYPES = %w(date enum html linklist markdown multienum string text).freeze
11
9
 
12
10
  self.primary_key = :attribute_id
13
11
 
14
- has_and_belongs_to_many :obj_class_definitions, :class_name => '::RailsConnector::ObjClass',
15
- :join_table => "#{table_name_prefix}obj_class_attrs"
12
+ has_and_belongs_to_many :obj_class_definitions, class_name: "::RailsConnector::ObjClass",
13
+ join_table: "#{table_name_prefix}obj_class_attrs"
16
14
 
17
15
  alias_method :obj_class_defs, :obj_class_definitions
18
16
  alias_attribute :name, :attribute_name
@@ -20,22 +18,22 @@ module RailsConnector
20
18
 
21
19
  # The (human readable) title.
22
20
  def title(language = :de)
23
- blob_data['titles'].presence && blob_data['titles'][language.to_s]
21
+ blob_data["titles"].presence && blob_data["titles"][language.to_s]
24
22
  end
25
23
 
26
24
  # The description of the attribute.
27
25
  def help_text(language = :de)
28
- blob_data['helpTexts'].presence && blob_data['helpTexts'][language.to_s]
26
+ blob_data["helpTexts"].presence && blob_data["helpTexts"][language.to_s]
29
27
  end
30
28
 
31
29
  # Searchable in Content Manager.
32
30
  def searchable_in_cm?
33
- blob_data['isSearchableInCM'].to_i != 0
31
+ blob_data["isSearchableInCM"].to_i != 0
34
32
  end
35
33
 
36
34
  # Returns the possible values if attribute is of type `enum' or `multienum'.
37
35
  def values
38
- blob_data['values']
36
+ blob_data["values"]
39
37
  end
40
38
 
41
39
  def max_size
@@ -55,7 +53,7 @@ module RailsConnector
55
53
  end
56
54
 
57
55
  TYPES.each do |type|
58
- self.class_eval <<EOM, __FILE__, __LINE__ + 1
56
+ class_eval <<EOM, __FILE__, __LINE__ + 1
59
57
  def #{type}?
60
58
  self.attribute_type == "#{type}"
61
59
  end
@@ -64,22 +62,23 @@ EOM
64
62
 
65
63
  # Convenience method for find_by_attribute_name
66
64
  def self.find_by_name(*args)
67
- self.find_by_attribute_name(*args)
65
+ find_by_attribute_name(*args)
68
66
  end
69
67
 
70
68
  # Returns the blob as a JSON object.
71
69
  def self.read_blob_data(name) #:nodoc:
72
- blob = RailsConnector::Meta.hello_im_rails_and_im_retarted_so_please_be_patient do # these queries really pollute our logs!
73
- blob_name = if RailsConnector::BlobMapping.exists?
74
- RailsConnector::BlobMapping.get_fingerprint("#{name}.jsonAttributeDict")
75
- else
76
- "#{name}.jsonAttributeDict"
77
- end
70
+ blob = RailsConnector::Meta.hello_im_rails_and_im_retarted_so_please_be_patient do # these queries really pollute our logs!
71
+ blob_name =
72
+ if RailsConnector::BlobMapping.exists?
73
+ RailsConnector::BlobMapping.get_fingerprint("#{name}.jsonAttributeDict")
74
+ else
75
+ "#{name}.jsonAttributeDict"
76
+ end
78
77
 
79
78
  RailsConnector::Blob.find_without_excluded_blob_data(blob_name)
80
79
  end
81
80
 
82
- return {} unless blob && blob.blob_data?
81
+ return {} unless blob&.blob_data?
83
82
 
84
83
  JSON.parse(blob.blob_data)
85
84
  end
@@ -88,9 +87,7 @@ EOM
88
87
 
89
88
  # load attribute details from blob
90
89
  def blob_data #:nodoc:
91
- @blob_data ||= self.class.read_blob_data(self.attribute_name)
90
+ @blob_data ||= self.class.read_blob_data(attribute_name)
92
91
  end
93
-
94
92
  end
95
-
96
93
  end
@@ -5,6 +5,7 @@ module RailsConnector
5
5
  unless instance_method_defined?(mod, method_name)
6
6
  mod.class_eval do
7
7
  private
8
+
8
9
  define_method(method_name, InstanceMethods.method(method_name).to_proc)
9
10
  end
10
11
  end
@@ -14,12 +15,18 @@ module RailsConnector
14
15
  end
15
16
 
16
17
  module InstanceMethods
17
- def self.logged_in?; false; end
18
- def self.admin?; false; end
19
- def self.current_user; nil; end
20
- end
18
+ def self.logged_in?
19
+ false
20
+ end
21
21
 
22
- private
22
+ def self.admin?
23
+ false
24
+ end
25
+
26
+ def self.current_user
27
+ nil
28
+ end
29
+ end
23
30
 
24
31
  def self.instance_method_defined?(mod, method_name)
25
32
  (
@@ -1,9 +1,8 @@
1
1
  require "json"
2
- require 'openssl'
3
- require 'rails_connector/fiona_datetime'
2
+ require "openssl"
3
+ require "rails_connector/fiona_datetime"
4
4
 
5
5
  module RailsConnector
6
-
7
6
  # The CMS file class
8
7
  #
9
8
  # [children] an Array of objects, Obj, of which this one is the parent
@@ -17,8 +16,7 @@ module RailsConnector
17
16
  "\xdf\x20\xbd\x42\x9a\x65\x8d\x72\x93\x6c\x96\x69\x91\x6e".freeze
18
17
 
19
18
  PREDEFINED_ATTRIBUTES = %w(blob body title channels sort_key1 sort_type1 sort_key2 sort_type2
20
- sort_key3 sort_type3 sort_order).freeze
21
-
19
+ sort_key3 sort_type3 sort_order).freeze
22
20
 
23
21
  self.store_full_sti_class = false
24
22
 
@@ -32,7 +30,7 @@ module RailsConnector
32
30
  when :released then configure_column_information("objs", true)
33
31
  when :edited
34
32
  configure_column_information("preview_objs", false)
35
- has_many(:arel_permissions, :class_name => "::RailsConnector::Permission", :foreign_key => "object_id")
33
+ has_many(:arel_permissions, class_name: "::RailsConnector::Permission", foreign_key: "object_id")
36
34
  else
37
35
  raise "configure_for_content called with unknown parameter #{which}"
38
36
  end
@@ -54,28 +52,32 @@ module RailsConnector
54
52
  RailsConnector::Meta::EagerLoader.instance.obj_classes.each do |class_name, obj_class|
55
53
  next unless obj_class
56
54
 
57
- if class_name =~ /^[A-Z]/
58
- klass = class_name.safe_constantize
59
- next unless klass
60
- if klass < RailsConnector::BasicObj
61
- klass.initialize_attributes
62
- end
63
- end
55
+ next unless /^[A-Z]/.match?(class_name)
56
+
57
+ klass = class_name.safe_constantize
58
+ next unless klass
59
+
60
+ klass.initialize_attributes if klass < RailsConnector::BasicObj
64
61
  end
65
62
  end
66
63
 
67
64
  def self.initialize_attributes
68
65
  PREDEFINED_ATTRIBUTES.each do |attribute|
69
- self.send(:define_attribute, attribute, ActiveRecord::Type::String.new)
66
+ send(:define_attribute, attribute, ActiveRecord::Type::String.new)
70
67
  end
71
68
 
72
69
  return if obj_class_definition.blank?
73
70
 
74
71
  obj_class_definition.custom_attributes.each_key do |attribute|
75
- self.send(:define_attribute, attribute, ActiveRecord::Type::String.new)
72
+ send(:define_attribute, attribute, ActiveRecord::Type::String.new)
76
73
  end
77
74
  end
78
75
 
76
+ def self.reinitialize_attributes
77
+ reset_obj_class_def
78
+ initialize_attributes
79
+ end
80
+
79
81
  def self.delegate_attributes
80
82
  PREDEFINED_ATTRIBUTES.each do |attribute|
81
83
  delegate attribute, to: :attr_dict
@@ -125,8 +127,8 @@ module RailsConnector
125
127
  end
126
128
 
127
129
  def self.reset_reflections
128
- has_many :children, :class_name => 'Obj', :foreign_key => 'parent_obj_id'
129
- belongs_to :parent, :class_name => 'Obj', :foreign_key => 'parent_obj_id'
130
+ has_many :children, class_name: "Obj", foreign_key: "parent_obj_id", validate: false
131
+ belongs_to :parent, class_name: "Obj", foreign_key: "parent_obj_id"
130
132
  end
131
133
 
132
134
  # @api public
@@ -189,7 +191,7 @@ module RailsConnector
189
191
  # and thus requires no extra database access.
190
192
  # @api public
191
193
  def homepage?
192
- self.id == (@@homepage_id ||= self.class.homepage.id)
194
+ id == (@@homepage_id ||= self.class.homepage.id)
193
195
  end
194
196
 
195
197
  # This method is used to calculate a part of a URL of an obj.
@@ -208,15 +210,17 @@ module RailsConnector
208
210
  # Returns the title of the content or the name.
209
211
  # @api public
210
212
  def display_title
211
- self.title || name
213
+ title || name
212
214
  end
213
215
 
214
- OBJECT_TYPES = {
215
- '2' => :document,
216
- '5' => :publication,
217
- 'B' => :image,
218
- 'C' => :generic
219
- }.freeze unless defined?(OBJECT_TYPES)
216
+ unless defined?(OBJECT_TYPES)
217
+ OBJECT_TYPES = {
218
+ "2" => :document,
219
+ "5" => :publication,
220
+ "B" => :image,
221
+ "C" => :generic
222
+ }.freeze
223
+ end
220
224
 
221
225
  # Returns the type of the object: :document, :publication, :image or :generic
222
226
  # @api public
@@ -227,7 +231,7 @@ module RailsConnector
227
231
  # Returns true if image? or generic?
228
232
  # @api public
229
233
  def binary?
230
- [:image, :generic].include? object_type
234
+ %i(image generic).include? object_type
231
235
  end
232
236
 
233
237
  # Returns true if object_type == :image
@@ -257,7 +261,8 @@ module RailsConnector
257
261
  # Returns true if this object is active.
258
262
  # @api public
259
263
  def active?
260
- return false if !valid_from
264
+ return false unless valid_from
265
+
261
266
  valid_from <= Time.now && (!valid_until || Time.now <= valid_until)
262
267
  end
263
268
 
@@ -311,14 +316,14 @@ module RailsConnector
311
316
  def root?
312
317
  parent_obj_id.nil?
313
318
  end
314
- #
315
319
 
316
320
  # Returns a list of exportable? children excluding the binary? ones unless :all is specfied.
317
321
  # This is mainly used for navigations.
318
322
  # @api public
319
323
  def toclist(*args)
320
324
  return [] unless publication?
321
- toclist = children.to_a.select{ |toc| toc.exportable? }
325
+
326
+ toclist = children.to_a.select { |toc| toc.exportable? }
322
327
  toclist = toclist.reject { |toc| toc.binary? } unless args.include?(:all)
323
328
  toclist
324
329
  end
@@ -326,20 +331,20 @@ module RailsConnector
326
331
  # Returns the sorted +toclist+, respecting sort order and type of this Obj.
327
332
  # @api public
328
333
  def sorted_toclist(*args)
329
- list = self.toclist(*args)
334
+ list = toclist(*args)
330
335
  return [] if list.blank?
331
336
 
332
- cached_sort_key1 = self.sort_key1
333
- cached_sort_type1 = self.sort_type1
337
+ cached_sort_key1 = sort_key1
338
+ cached_sort_type1 = sort_type1
334
339
 
335
340
  sorted_list =
336
341
  if cached_sort_key1.blank?
337
- list.sort { |left_obj, right_obj| left_obj.name <=> right_obj.name }
342
+ list.sort_by(&:name)
338
343
  else
339
- cached_sort_key2 = self.sort_key2
340
- cached_sort_type2 = self.sort_type2
341
- cached_sort_key3 = self.sort_key3
342
- cached_sort_type3 = self.sort_type3
344
+ cached_sort_key2 = sort_key2
345
+ cached_sort_type2 = sort_type2
346
+ cached_sort_key3 = sort_key3
347
+ cached_sort_type3 = sort_type3
343
348
 
344
349
  list.sort do |left_obj, right_obj|
345
350
  compare = compare_on_sort_key(left_obj, right_obj, cached_sort_key1, cached_sort_type1)
@@ -353,7 +358,7 @@ module RailsConnector
353
358
  end
354
359
  end
355
360
 
356
- return self.sort_order == "descending" ? sorted_list.reverse : sorted_list
361
+ sort_order == "descending" ? sorted_list.reverse : sorted_list
357
362
  end
358
363
 
359
364
  # Returns an Array of all the ancestor objects, starting at the root and ending at this object's parent.
@@ -370,9 +375,10 @@ module RailsConnector
370
375
  # returns nil if no object with the given name was found.
371
376
  # @api public
372
377
  def find_nearest(name)
373
- obj = self.children.find_by_name(name)
374
- return obj if obj and obj.active?
375
- parent.find_nearest(name) unless self.root?
378
+ obj = children.find_by_name(name)
379
+ return obj if obj&.active?
380
+
381
+ parent.find_nearest(name) unless root?
376
382
  end
377
383
 
378
384
  # Returns the value of the attribute specified by its name.
@@ -382,9 +388,7 @@ module RailsConnector
382
388
  def [](key)
383
389
  if has_attribute?(key)
384
390
  begin
385
- if attr_dict.respond_to?(key)
386
- return attr_dict.send(key)
387
- end
391
+ return attr_dict.send(key) if attr_dict.respond_to?(key)
388
392
 
389
393
  read_attribute(key)
390
394
  rescue NoMethodError
@@ -455,11 +459,13 @@ module RailsConnector
455
459
  @attr_values ||= begin
456
460
  encoded_and_encrypted_attr_values = read_attribute(:attr_values)
457
461
  return {} unless encoded_and_encrypted_attr_values
462
+
458
463
  encrypted_attr_values = Base64.decode64(encoded_and_encrypted_attr_values)
459
- if !encrypted_attr_values.starts_with?('Salted__') || encrypted_attr_values.length < 16
460
- raise 'attr_values has wrong format'
464
+ if !encrypted_attr_values.starts_with?("Salted__") || encrypted_attr_values.length < 16
465
+ raise "attr_values has wrong format"
461
466
  end
462
- cipher = OpenSSL::Cipher.new('rc4')
467
+
468
+ cipher = OpenSSL::Cipher.new("rc4")
463
469
  cipher.decrypt
464
470
  salt = encrypted_attr_values[8..15]
465
471
  cipher.pkcs5_keyivgen(CRYPT_KEY, salt, 1)
@@ -501,13 +507,13 @@ module RailsConnector
501
507
  @mime_type ||= compute_mime_type
502
508
  end
503
509
 
504
- def respond_to?(method_id, include_private=false)
510
+ def respond_to?(method_id, include_private = false)
505
511
  if super
506
512
  true
507
513
  elsif %w(_attr_dict _attr_defs _attr_values).include?(method_id.to_s)
508
514
  # prevent infinite recursion when calling "attr_*" below,
509
515
  # since rails checks the absence of an "_attr_*" method internally
510
- return false
516
+ false
511
517
  else
512
518
  attr_dict.respond_to?(method_id)
513
519
  end
@@ -517,18 +523,18 @@ module RailsConnector
517
523
 
518
524
  def fiona_fields
519
525
  @fiona_fields ||=
520
- ['name', 'obj_class', 'workflow', 'suppressexport', 'permalink'].inject({}) do |all,field|
526
+ %w(name obj_class workflow suppressexport permalink).inject({}) do |all, field|
521
527
  all.merge! field => {
522
- 'titles' => {'de' => field.humanize, 'en' => field.humanize},
523
- 'type' => 'string',
524
- 'help_texts' => {'de' => field, 'en' => field}
528
+ "titles" => { "de" => field.humanize, "en" => field.humanize },
529
+ "type" => "string",
530
+ "help_texts" => { "de" => field, "en" => field }
525
531
  }
526
532
  end
527
533
  end
528
534
 
529
535
  def compute_mime_type
530
536
  MIME::Types.type_for(file_extension).first.content_type
531
- rescue
537
+ rescue StandardError
532
538
  binary? ? "application/octet-stream" : "text/plain"
533
539
  end
534
540
 
@@ -545,7 +551,15 @@ module RailsConnector
545
551
  left_value <=> right_value
546
552
  else
547
553
  if my_sort_type == "numeric"
548
- (left_value.to_i rescue 0) <=> (right_value.to_i rescue 0)
554
+ (begin
555
+ left_value.to_i
556
+ rescue StandardError
557
+ 0
558
+ end) <=> (begin
559
+ right_value.to_i
560
+ rescue StandardError
561
+ 0
562
+ end)
549
563
  else
550
564
  left_value.to_s.downcase <=> right_value.to_s.downcase
551
565
  end
@@ -558,7 +572,5 @@ module RailsConnector
558
572
  rescue NameError, ActiveRecord::ActiveRecordError
559
573
  nil
560
574
  end
561
-
562
575
  end
563
-
564
576
  end