active-fedora 13.3.0 → 14.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (96) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +106 -46
  3. data/.rubocop.yml +26 -12
  4. data/.rubocop_todo.yml +1 -1
  5. data/Gemfile +3 -3
  6. data/active-fedora.gemspec +11 -11
  7. data/lib/active_fedora/association_hash.rb +5 -2
  8. data/lib/active_fedora/associations/association.rb +2 -4
  9. data/lib/active_fedora/associations/association_scope.rb +1 -1
  10. data/lib/active_fedora/associations/basic_contains_association.rb +2 -2
  11. data/lib/active_fedora/associations/belongs_to_association.rb +1 -1
  12. data/lib/active_fedora/associations/builder/association.rb +3 -5
  13. data/lib/active_fedora/associations/builder/basic_contains.rb +1 -1
  14. data/lib/active_fedora/associations/builder/belongs_to.rb +3 -7
  15. data/lib/active_fedora/associations/builder/collection_association.rb +7 -7
  16. data/lib/active_fedora/associations/builder/directly_contains.rb +4 -6
  17. data/lib/active_fedora/associations/builder/directly_contains_one.rb +5 -6
  18. data/lib/active_fedora/associations/builder/has_and_belongs_to_many.rb +1 -1
  19. data/lib/active_fedora/associations/builder/has_many.rb +1 -1
  20. data/lib/active_fedora/associations/builder/has_subresource.rb +1 -1
  21. data/lib/active_fedora/associations/builder/indirectly_contains.rb +3 -6
  22. data/lib/active_fedora/associations/builder/singular_association.rb +1 -1
  23. data/lib/active_fedora/associations/collection_association.rb +3 -6
  24. data/lib/active_fedora/associations/container_proxy.rb +2 -0
  25. data/lib/active_fedora/associations/contains_association.rb +2 -2
  26. data/lib/active_fedora/associations/directly_contains_association.rb +7 -9
  27. data/lib/active_fedora/associations/directly_contains_one_association.rb +2 -2
  28. data/lib/active_fedora/associations/has_and_belongs_to_many_association.rb +1 -1
  29. data/lib/active_fedora/associations/has_many_association.rb +4 -2
  30. data/lib/active_fedora/associations/has_subresource_association.rb +2 -4
  31. data/lib/active_fedora/associations/indirectly_contains_association.rb +10 -12
  32. data/lib/active_fedora/associations/orders_association.rb +7 -14
  33. data/lib/active_fedora/associations/rdf.rb +2 -2
  34. data/lib/active_fedora/associations/record_composite.rb +1 -0
  35. data/lib/active_fedora/associations/singular_association.rb +3 -1
  36. data/lib/active_fedora/associations/singular_rdf.rb +1 -1
  37. data/lib/active_fedora/associations.rb +3 -3
  38. data/lib/active_fedora/attached_files.rb +5 -3
  39. data/lib/active_fedora/attribute_assignment.rb +2 -4
  40. data/lib/active_fedora/attribute_methods/read.rb +1 -1
  41. data/lib/active_fedora/attribute_methods/write.rb +4 -6
  42. data/lib/active_fedora/attribute_methods.rb +7 -7
  43. data/lib/active_fedora/attributes/property_builder.rb +1 -1
  44. data/lib/active_fedora/attributes.rb +1 -1
  45. data/lib/active_fedora/autosave_association.rb +4 -4
  46. data/lib/active_fedora/callbacks.rb +3 -3
  47. data/lib/active_fedora/change_set.rb +5 -7
  48. data/lib/active_fedora/cleaner.rb +1 -1
  49. data/lib/active_fedora/core/fedora_id_translator.rb +1 -3
  50. data/lib/active_fedora/core.rb +6 -13
  51. data/lib/active_fedora/errors.rb +3 -3
  52. data/lib/active_fedora/fedora.rb +3 -7
  53. data/lib/active_fedora/file/attributes.rb +5 -5
  54. data/lib/active_fedora/file.rb +1 -1
  55. data/lib/active_fedora/file_configurator.rb +16 -14
  56. data/lib/active_fedora/file_io.rb +2 -4
  57. data/lib/active_fedora/files_hash.rb +2 -2
  58. data/lib/active_fedora/fixity_service.rb +5 -5
  59. data/lib/active_fedora/identifiable.rb +2 -18
  60. data/lib/active_fedora/indexing/default_descriptors.rb +3 -5
  61. data/lib/active_fedora/indexing/descendant_fetcher.rb +3 -3
  62. data/lib/active_fedora/indexing/descriptor.rb +1 -1
  63. data/lib/active_fedora/indexing/field_mapper.rb +3 -5
  64. data/lib/active_fedora/indexing.rb +9 -5
  65. data/lib/active_fedora/indexing_service.rb +2 -2
  66. data/lib/active_fedora/inheritance.rb +1 -3
  67. data/lib/active_fedora/ldp_resource.rb +3 -3
  68. data/lib/active_fedora/loadable_from_json.rb +5 -3
  69. data/lib/active_fedora/model_classifier.rb +2 -2
  70. data/lib/active_fedora/nested_attributes.rb +11 -21
  71. data/lib/active_fedora/null_logger.rb +2 -0
  72. data/lib/active_fedora/orders/list_node.rb +2 -3
  73. data/lib/active_fedora/orders/ordered_list.rb +16 -22
  74. data/lib/active_fedora/orders/target_proxy.rb +1 -1
  75. data/lib/active_fedora/querying.rb +1 -1
  76. data/lib/active_fedora/rdf/fcrepo.rb +3 -0
  77. data/lib/active_fedora/rdf/field_map.rb +0 -1
  78. data/lib/active_fedora/rdf/persistence.rb +1 -1
  79. data/lib/active_fedora/reflection.rb +8 -11
  80. data/lib/active_fedora/relation/finder_methods.rb +6 -12
  81. data/lib/active_fedora/relation/spawn_methods.rb +1 -1
  82. data/lib/active_fedora/runtime_registry.rb +2 -4
  83. data/lib/active_fedora/scoping/default.rb +2 -4
  84. data/lib/active_fedora/scoping/named.rb +1 -3
  85. data/lib/active_fedora/scoping.rb +2 -2
  86. data/lib/active_fedora/serialization.rb +1 -1
  87. data/lib/active_fedora/solr_service.rb +1 -3
  88. data/lib/active_fedora/version.rb +1 -1
  89. data/lib/active_fedora/versionable.rb +2 -2
  90. data/lib/active_fedora/versions_graph.rb +4 -6
  91. data/lib/active_fedora/with_metadata/metadata_node.rb +1 -1
  92. data/lib/active_fedora/with_metadata.rb +1 -1
  93. data/lib/active_fedora.rb +5 -7
  94. data/lib/generators/active_fedora/config/solr/templates/solr/conf/solrconfig.xml +3 -1
  95. data/lib/tasks/active_fedora_dev.rake +5 -5
  96. metadata +25 -52
@@ -47,11 +47,9 @@ module ActiveFedora
47
47
  # to.
48
48
  # @note This can only be run on an unpersisted resource.
49
49
  def uri=(uri)
50
- if persisted?
51
- raise AlreadyPersistedError, "You can not set a URI for a persisted ActiveFedora object."
52
- else
53
- @ldp_source = build_ldp_resource(self.class.uri_to_id(uri))
54
- end
50
+ raise AlreadyPersistedError, "You can not set a URI for a persisted ActiveFedora object." if persisted?
51
+
52
+ @ldp_source = build_ldp_resource(self.class.uri_to_id(uri))
55
53
  end
56
54
 
57
55
  # Reloads the object from Fedora.
@@ -132,9 +130,7 @@ module ActiveFedora
132
130
  # Returns a suitable string representation for :has_model
133
131
  # @deprecated use to_rdf_representation instead
134
132
  def to_class_uri(attrs = nil)
135
- if attrs
136
- Deprecation.warn ActiveFedora::Core, "to_class_uri no longer acceps an argument"
137
- end
133
+ Deprecation.warn ActiveFedora::Core, "to_class_uri no longer acceps an argument" if attrs
138
134
  to_rdf_representation
139
135
  end
140
136
  deprecation_deprecate to_class_uri: "use 'to_rdf_representation()' instead"
@@ -159,11 +155,8 @@ module ActiveFedora
159
155
  end
160
156
 
161
157
  def check_persistence
162
- if destroyed?
163
- raise ActiveFedora::ObjectNotFoundError, "Can't reload an object that has been destroyed"
164
- else
165
- raise ActiveFedora::ObjectNotFoundError, "Can't reload an object that hasn't been saved"
166
- end
158
+ raise ActiveFedora::ObjectNotFoundError, "Can't reload an object that has been destroyed" if destroyed?
159
+ raise ActiveFedora::ObjectNotFoundError, "Can't reload an object that hasn't been saved"
167
160
  end
168
161
  end
169
162
  end
@@ -1,4 +1,4 @@
1
- module ActiveFedora #:nodoc:
1
+ module ActiveFedora # :nodoc:
2
2
  # Generic ActiveFedora exception class
3
3
  class ActiveFedoraError < StandardError
4
4
  end
@@ -37,7 +37,7 @@ module ActiveFedora #:nodoc:
37
37
  class AssociationTypeMismatch < ActiveFedoraError
38
38
  end
39
39
 
40
- class AssociationNotFoundError < ConfigurationError #:nodoc:
40
+ class AssociationNotFoundError < ConfigurationError # :nodoc:
41
41
  end
42
42
 
43
43
  # Raised when an object is loaded from Fedora by an incompatible class
@@ -47,7 +47,7 @@ module ActiveFedora #:nodoc:
47
47
  # This error is raised when trying to destroy a parent instance in N:1 or 1:1 associations
48
48
  # (has_many, has_one) when there is at least 1 child associated instance.
49
49
  # ex: if @project.tasks.size > 0, DeleteRestrictionError will be raised when trying to destroy @project
50
- class DeleteRestrictionError < ActiveFedoraError #:nodoc:
50
+ class DeleteRestrictionError < ActiveFedoraError # :nodoc:
51
51
  def initialize(name = nil)
52
52
  if name
53
53
  super("Cannot delete record because of dependent #{name}")
@@ -54,9 +54,7 @@ module ActiveFedora
54
54
  end
55
55
 
56
56
  def connection
57
- @connection ||= begin
58
- build_connection
59
- end
57
+ @connection ||= build_connection
60
58
  end
61
59
 
62
60
  def clean_connection
@@ -94,14 +92,12 @@ module ActiveFedora
94
92
  Faraday.new(host, options) do |conn|
95
93
  conn.response :encoding # use Faraday::Encoding middleware
96
94
  conn.adapter Faraday.default_adapter # net/http
97
- conn.basic_auth(user, password)
95
+ conn.request :basic_auth, user, password
98
96
  end
99
97
  end
100
98
 
101
99
  def validate_options
102
- unless host.downcase.end_with?("/rest")
103
- ActiveFedora::Base.logger.warn "Fedora URL (#{host}) does not end with /rest. This could be a problem. Check your fedora.yml config"
104
- end
100
+ ActiveFedora::Base.logger.warn "Fedora URL (#{host}) does not end with /rest. This could be a problem. Check your fedora.yml config" unless host.downcase.end_with?("/rest")
105
101
  end
106
102
 
107
103
  def ntriples_connection
@@ -18,9 +18,9 @@ module ActiveFedora::File::Attributes
18
18
  end
19
19
 
20
20
  def digest
21
- response = metadata.ldp_source.graph.query(predicate: RDF::Vocab::PREMIS.hasMessageDigest)
21
+ response = metadata.ldp_source.graph.query({ predicate: RDF::Vocab::PREMIS.hasMessageDigest })
22
22
  # fallback on old predicate for checksum
23
- response = metadata.ldp_source.graph.query(predicate: fallback_digest_predicate) if response.empty?
23
+ response = metadata.ldp_source.graph.query({ predicate: fallback_digest_predicate }) if response.empty?
24
24
  response.map(&:object)
25
25
  end
26
26
 
@@ -37,7 +37,7 @@ module ActiveFedora::File::Attributes
37
37
  end
38
38
 
39
39
  def has_content?
40
- size && size > 0
40
+ size&.positive?
41
41
  end
42
42
 
43
43
  def empty?
@@ -46,12 +46,12 @@ module ActiveFedora::File::Attributes
46
46
 
47
47
  def create_date
48
48
  created = metadata.attributes["http://fedora.info/definitions/v4/repository#created"]
49
- created && created.first
49
+ created&.first
50
50
  end
51
51
 
52
52
  def modified_date
53
53
  modified = metadata.attributes["http://fedora.info/definitions/v4/repository#lastModified"]
54
- modified && modified.first
54
+ modified&.first
55
55
  end
56
56
 
57
57
  private
@@ -111,7 +111,7 @@ module ActiveFedora
111
111
  end
112
112
 
113
113
  def content_changed?
114
- return true if new_record? && !local_or_remote_content(false).blank?
114
+ return true if new_record? && local_or_remote_content(false).present?
115
115
  local_or_remote_content(false) != @ds_content
116
116
  end
117
117
 
@@ -54,9 +54,7 @@ module ActiveFedora
54
54
  end
55
55
 
56
56
  def init(options = {})
57
- if options.is_a?(String)
58
- raise ArgumentError, "Calling ActiveFedora.init with a path as an argument has been removed. Use ActiveFedora.init(:fedora_config_path=>#{options})"
59
- end
57
+ raise ArgumentError, "Calling ActiveFedora.init with a path as an argument has been removed. Use ActiveFedora.init(:fedora_config_path=>#{options})" if options.is_a?(String)
60
58
  reset!
61
59
  @config_options = options
62
60
  load_configs
@@ -108,7 +106,11 @@ module ActiveFedora
108
106
  end
109
107
 
110
108
  begin
111
- fedora_yml = YAML.safe_load(config_erb, [], [], true) # allow YAML aliases
109
+ fedora_yml = if Gem::Version.new(Psych::VERSION) >= Gem::Version.new('3.1.0.pre1')
110
+ YAML.safe_load(config_erb, permitted_classes: [], permitted_symbols: [], aliases: true)
111
+ else
112
+ YAML.safe_load(config_erb, [], [], true) # allow YAML aliases
113
+ end
112
114
  rescue Psych::SyntaxError => e
113
115
  raise "fedora.yml was found, but could not be parsed. " \
114
116
  "Error #{e.message}"
@@ -132,7 +134,11 @@ module ActiveFedora
132
134
  end
133
135
 
134
136
  begin
135
- solr_yml = YAML.safe_load(config_erb, [], [], true) # allow YAML aliases
137
+ solr_yml = if Gem::Version.new(Psych::VERSION) >= Gem::Version.new('3.1.0.pre1')
138
+ YAML.safe_load(config_erb, permitted_classes: [], permitted_symbols: [], aliases: true)
139
+ else
140
+ YAML.safe_load(config_erb, [], [], true) # allow YAML aliases
141
+ end
136
142
  rescue StandardError
137
143
  raise("solr.yml was found, but could not be parsed.\n")
138
144
  end
@@ -181,18 +187,14 @@ module ActiveFedora
181
187
  return config_path if ::File.file? config_path
182
188
  end
183
189
 
184
- if ::File.file? "#{Dir.getwd}/config/#{config_type}.yml"
185
- return "#{Dir.getwd}/config/#{config_type}.yml"
186
- end
190
+ return "#{Dir.getwd}/config/#{config_type}.yml" if ::File.file? "#{Dir.getwd}/config/#{config_type}.yml"
187
191
 
188
192
  # Last choice, check for the default config file
189
193
  config_path = ::File.join(ActiveFedora.root, "config", "#{config_type}.yml")
190
- if ::File.file? config_path
191
- ActiveFedora::Base.logger.warn "Using the default #{config_type}.yml that comes with active-fedora. If you want to override this, pass the path to #{config_type}.yml to ActiveFedora - ie. ActiveFedora.init(:#{config_type}_config_path => '/path/to/#{config_type}.yml') - or set Rails.root and put #{config_type}.yml into \#{Rails.root}/config."
192
- return config_path
193
- else
194
- raise ConfigurationError, "Couldn't load #{config_type} config file!"
195
- end
194
+ raise ConfigurationError, "Couldn't load #{config_type} config file!" unless ::File.file?(config_path)
195
+
196
+ ActiveFedora::Base.logger.warn "Using the default #{config_type}.yml that comes with active-fedora. If you want to override this, pass the path to #{config_type}.yml to ActiveFedora - ie. ActiveFedora.init(:#{config_type}_config_path => '/path/to/#{config_type}.yml') - or set Rails.root and put #{config_type}.yml into \#{Rails.root}/config."
197
+ config_path
196
198
  end
197
199
 
198
200
  # Checks the existing fedora_config.path to see if there is a solr.yml there
@@ -49,7 +49,7 @@ module ActiveFedora
49
49
 
50
50
  if amount.nil?
51
51
  read_to_buf(nil, buf) # read the entire file, returns buf
52
- elsif amount < 0
52
+ elsif amount.negative?
53
53
  raise(ArgumentError, "negative length #{amount} given")
54
54
  elsif amount.zero?
55
55
  ''
@@ -89,9 +89,7 @@ module ActiveFedora
89
89
  private
90
90
 
91
91
  def read_to_buf(amount, buf)
92
- while (amount.nil? || buf.length < amount) && fill_buffer
93
- buf << consume_buffer(amount.nil? ? nil : (amount - buf.length))
94
- end
92
+ buf << consume_buffer(amount.nil? ? nil : (amount - buf.length)) while (amount.nil? || buf.length < amount) && fill_buffer
95
93
  buf
96
94
  end
97
95
 
@@ -1,7 +1,7 @@
1
1
  module ActiveFedora
2
2
  class FilesHash < AssociationHash
3
- def initialize(model)
4
- @base = model
3
+ def initialize(model, reflections = nil)
4
+ super
5
5
  end
6
6
 
7
7
  def reflections
@@ -31,19 +31,19 @@ module ActiveFedora
31
31
  # An array of 1 or more literals reported by Fedora.
32
32
  # See 'success' for which one indicates fixity check is good.
33
33
  def status
34
- fixity_graph.query(predicate: premis_status_predicate).map(&:object) +
35
- fixity_graph.query(predicate: fedora_status_predicate).map(&:object)
34
+ fixity_graph.query({ predicate: premis_status_predicate }).map(&:object) +
35
+ fixity_graph.query({ predicate: fedora_status_predicate }).map(&:object)
36
36
  end
37
37
 
38
38
  # the currently calculated checksum, as a string URI, like
39
39
  # "urn:sha1:09a848b79f86f3a4f3f301b8baafde455d6f8e0e"
40
40
  def expected_message_digest
41
- fixity_graph.query(predicate: ::RDF::Vocab::PREMIS.hasMessageDigest).first.try(:object).try(:to_s)
41
+ fixity_graph.query({ predicate: ::RDF::Vocab::PREMIS.hasMessageDigest }).first.try(:object).try(:to_s)
42
42
  end
43
43
 
44
44
  # integer, as reported by fedora. bytes maybe?
45
45
  def expected_size
46
- fixity_graph.query(predicate: ::RDF::Vocab::PREMIS.hasSize).first.try(:object).try(:to_s).try(:to_i)
46
+ fixity_graph.query({ predicate: ::RDF::Vocab::PREMIS.hasSize }).first.try(:object).try(:to_s).try(:to_i)
47
47
  end
48
48
 
49
49
  # Fedora response as an ::RDF::Graph object. Public API, so consumers
@@ -83,7 +83,7 @@ module ActiveFedora
83
83
  # See https://jira.duraspace.org/browse/FCREPO-1247
84
84
  # @param [String] uri
85
85
  def encoded_url(uri)
86
- if uri =~ /fcr:versions/
86
+ if /fcr:versions/.match?(uri)
87
87
  uri.gsub(/fcr:versions/, "fcr%3aversions")
88
88
  else
89
89
  uri
@@ -7,29 +7,13 @@ module ActiveFedora
7
7
  # :singleton-method
8
8
  #
9
9
  # Accepts a proc that takes an id and transforms it to a URI
10
- mattr_reader :translate_id_to_uri
11
-
12
- # This method is mixed into ActiveFedora::Base and ActiveFedora::File, so don't
13
- # overwrite the value if it's already set.
14
- @@translate_id_to_uri ||= Core::FedoraIdTranslator
15
-
16
- def self.translate_id_to_uri=(translator)
17
- @@translate_id_to_uri = translator || Core::FedoraIdTranslator
18
- end
10
+ mattr_accessor :translate_id_to_uri, default: Core::FedoraIdTranslator
19
11
 
20
12
  ##
21
13
  # :singleton-method
22
14
  #
23
15
  # Accepts a proc that takes a uri and transforms it to an id
24
- mattr_reader :translate_uri_to_id
25
-
26
- # This method is mixed into ActiveFedora::Base and ActiveFedora::File, so don't
27
- # overwrite the value if it's already set.
28
- @@translate_uri_to_id ||= Core::FedoraUriTranslator
29
-
30
- def self.translate_uri_to_id=(translator)
31
- @@translate_uri_to_id = translator || Core::FedoraUriTranslator
32
- end
16
+ mattr_accessor :translate_uri_to_id, default: Core::FedoraUriTranslator
33
17
  end
34
18
 
35
19
  def id
@@ -104,11 +104,9 @@ module ActiveFedora
104
104
  def dateable_converter
105
105
  lambda do |_type|
106
106
  lambda do |val|
107
- begin
108
- iso8601_date(Date.parse(val))
109
- rescue ArgumentError
110
- nil
111
- end
107
+ iso8601_date(Date.parse(val))
108
+ rescue ArgumentError
109
+ nil
112
110
  end
113
111
  end
114
112
  end
@@ -23,7 +23,7 @@ module ActiveFedora
23
23
  HAS_MODEL_PREDICATE = ActiveFedora::RDF::Fcrepo::Model.hasModel
24
24
 
25
25
  class_attribute :default_priority_models, instance_accessor: false
26
- self.default_priority_models = %w(Hydra::AccessControl Hydra::AccessControl::Permissions).freeze
26
+ self.default_priority_models = %w[Hydra::AccessControl Hydra::AccessControl::Permissions].freeze
27
27
 
28
28
  attr_reader :uri, :priority_models
29
29
 
@@ -59,7 +59,7 @@ module ActiveFedora
59
59
 
60
60
  add_self_to_partitioned_uris unless @exclude_self
61
61
 
62
- rdf_graph.query(predicate: ::RDF::Vocab::LDP.contains).each_object do |uri|
62
+ rdf_graph.query({ predicate: ::RDF::Vocab::LDP.contains }).each_object do |uri|
63
63
  descendant_uri = uri.to_s
64
64
  self.class.new(
65
65
  descendant_uri,
@@ -89,7 +89,7 @@ module ActiveFedora
89
89
  end
90
90
 
91
91
  def add_self_to_partitioned_uris
92
- rdf_graph.query(predicate: HAS_MODEL_PREDICATE).each_object do |model|
92
+ rdf_graph.query({ predicate: HAS_MODEL_PREDICATE }).each_object do |model|
93
93
  next unless model.literal?
94
94
 
95
95
  partitioned_uris[model.to_s] ||= []
@@ -37,7 +37,7 @@ module ActiveFedora
37
37
  end
38
38
 
39
39
  def converter(field_type)
40
- @converter.call(field_type) if @converter
40
+ @converter&.call(field_type)
41
41
  end
42
42
  end
43
43
  end
@@ -122,11 +122,9 @@ module ActiveFedora
122
122
  # search through the descriptors (class attribute) until a module is found that responds to index_type, then call it.
123
123
  def index_type_macro(index_type)
124
124
  klass = self.class.descriptors.find { |descriptor_klass| descriptor_klass.respond_to? index_type }
125
- if klass
126
- klass.send(index_type)
127
- else
128
- raise UnknownIndexMacro, "Unable to find `#{index_type}' in #{self.class.descriptors}"
129
- end
125
+ raise UnknownIndexMacro, "Unable to find `#{index_type}' in #{self.class.descriptors}" unless klass
126
+
127
+ klass.send(index_type)
130
128
  end
131
129
 
132
130
  def extract_type(value)
@@ -47,9 +47,11 @@ module ActiveFedora
47
47
  end
48
48
 
49
49
  # Updates Solr index with self.
50
+ # rubocop:disable Naming/VariableName
50
51
  def update_index
51
52
  SolrService.add(to_solr, softCommit: true)
52
53
  end
54
+ # rubocop:enable Naming/VariableName
53
55
 
54
56
  protected
55
57
 
@@ -91,6 +93,7 @@ module ActiveFedora
91
93
  end
92
94
  end
93
95
 
96
+ # rubocop:disable Naming/VariableName
94
97
  # @param [Integer] batch_size - The number of Fedora objects to process for each SolrService.add call. Default 50.
95
98
  # @param [Boolean] softCommit - Do we perform a softCommit when we add the to_solr objects to SolrService. Default true.
96
99
  # @param [Boolean] progress_bar - If true output progress bar information. Default false.
@@ -113,7 +116,7 @@ module ActiveFedora
113
116
  batch.clear
114
117
  end
115
118
 
116
- progress_bar_controller.increment if progress_bar_controller
119
+ progress_bar_controller&.increment
117
120
  end
118
121
 
119
122
  if batch.present?
@@ -121,11 +124,12 @@ module ActiveFedora
121
124
  batch.clear
122
125
  end
123
126
 
124
- if final_commit
125
- logger.debug "Solr hard commit..."
126
- SolrService.commit
127
- end
127
+ return unless final_commit
128
+
129
+ logger.debug "Solr hard commit..."
130
+ SolrService.commit
128
131
  end
132
+ # rubocop:enable Naming/VariableName
129
133
 
130
134
  def descendant_uris(uri, exclude_uri: false)
131
135
  DescendantFetcher.new(uri, exclude_self: exclude_uri).descendant_and_self_uris
@@ -47,13 +47,13 @@ module ActiveFedora
47
47
  protected
48
48
 
49
49
  def c_time
50
- c_time = object.create_date.present? ? object.create_date : DateTime.now
50
+ c_time = object.create_date.presence || DateTime.now
51
51
  c_time = DateTime.parse(c_time) unless c_time.is_a?(DateTime)
52
52
  c_time
53
53
  end
54
54
 
55
55
  def m_time
56
- m_time = object.modified_date.present? ? object.modified_date : DateTime.now
56
+ m_time = object.modified_date.presence || DateTime.now
57
57
  m_time = DateTime.parse(m_time) unless m_time.is_a?(DateTime)
58
58
  m_time
59
59
  end
@@ -14,9 +14,7 @@ module ActiveFedora
14
14
  def base_class
15
15
  return File if self <= File
16
16
 
17
- unless self <= Base
18
- raise ActiveFedoraError, "#{name} doesn't belong in a hierarchy descending from ActiveFedora"
19
- end
17
+ raise ActiveFedoraError, "#{name} doesn't belong in a hierarchy descending from ActiveFedora" unless self <= Base
20
18
 
21
19
  if self == Base || superclass == Base || superclass.abstract_class?
22
20
  self
@@ -23,8 +23,8 @@ module ActiveFedora
23
23
 
24
24
  private
25
25
 
26
- def response_as_graph(resp)
27
- graph_class.new(subject_uri, data: resp.graph.data)
28
- end
26
+ def response_as_graph(resp)
27
+ graph_class.new(subject_uri, data: resp.graph.data)
28
+ end
29
29
  end
30
30
  end
@@ -147,9 +147,11 @@ module ActiveFedora
147
147
  # @param attrs [Hash] attributes read from Solr
148
148
  # @return [Hash] the adapted attributes
149
149
  def adapt_attributes(attrs)
150
- self.class.attribute_names.each_with_object({}) do |attribute_name, new_attributes|
151
- new_attributes[attribute_name] = adapt_attribute_value(attrs, attribute_name)
150
+ result = {}
151
+ self.class.attribute_names.each do |attribute_name|
152
+ result[attribute_name] = adapt_attribute_value(attrs, attribute_name)
152
153
  end
154
+ result
153
155
  end
154
156
 
155
157
  # Adapts a single attribute from the given attributes hash to fit the data
@@ -194,7 +196,7 @@ module ActiveFedora
194
196
  # @return [Object] the adapted value
195
197
  def adapt_single_attribute_value(value, attribute_name)
196
198
  if value && date_attribute?(attribute_name)
197
- return nil unless value.present?
199
+ return nil if value.blank?
198
200
  DateTime.parse(value)
199
201
  else
200
202
  value
@@ -69,9 +69,9 @@ module ActiveFedora
69
69
  def class_exists?(class_name)
70
70
  return false if class_name.empty?
71
71
  klass = class_name.constantize
72
- return klass.is_a?(Class)
72
+ klass.is_a?(Class)
73
73
  rescue NameError
74
- return false
74
+ false
75
75
  end
76
76
  end
77
77
  end
@@ -3,7 +3,7 @@ require 'active_support/core_ext/object/try'
3
3
  require 'active_support/core_ext/object/blank'
4
4
 
5
5
  module ActiveFedora
6
- module NestedAttributes #:nodoc:
6
+ module NestedAttributes # :nodoc:
7
7
  class TooManyRecords < RuntimeError
8
8
  end
9
9
 
@@ -160,7 +160,7 @@ module ActiveFedora
160
160
 
161
161
  # Attribute hash keys that should not be assigned as normal attributes.
162
162
  # These hash keys are nested attributes implementation details.
163
- UNASSIGNABLE_KEYS = %w(id _destroy).freeze
163
+ UNASSIGNABLE_KEYS = %w[id _destroy].freeze
164
164
 
165
165
  # Assigns the given attributes to the association.
166
166
  #
@@ -182,7 +182,7 @@ module ActiveFedora
182
182
  attributes = attributes.with_indifferent_access
183
183
  existing_record = send(association_name)
184
184
 
185
- if (options[:update_only] || !attributes['id'].blank?) && existing_record &&
185
+ if (options[:update_only] || attributes['id'].present?) && existing_record &&
186
186
  (options[:update_only] || existing_record.id.to_s == attributes['id'].to_s)
187
187
  assign_to_or_mark_for_destruction(existing_record, attributes, options[:allow_destroy]) unless call_reject_if(association_name, attributes)
188
188
 
@@ -192,16 +192,14 @@ module ActiveFedora
192
192
  elsif !reject_new_record?(association_name, attributes)
193
193
  assignable_attributes = attributes.except(*UNASSIGNABLE_KEYS)
194
194
 
195
- if existing_record && existing_record.new_record?
195
+ if existing_record&.new_record?
196
196
  existing_record.assign_attributes(assignable_attributes)
197
197
  association(association_name).initialize_attributes(existing_record)
198
198
  else
199
199
  method = "build_#{association_name}"
200
- if respond_to?(method)
201
- send(method, assignable_attributes)
202
- else
203
- raise ArgumentError, "Cannot build association `#{association_name}'. Are you trying to build a polymorphic one-to-one association?"
204
- end
200
+ raise ArgumentError, "Cannot build association `#{association_name}'. Are you trying to build a polymorphic one-to-one association?" unless respond_to?(method)
201
+
202
+ send(method, assignable_attributes)
205
203
  end
206
204
  end
207
205
  end
@@ -209,13 +207,9 @@ module ActiveFedora
209
207
  def assign_nested_attributes_for_collection_association(association_name, attributes_collection)
210
208
  options = nested_attributes_options[association_name]
211
209
 
212
- if attributes_collection.respond_to?(:permitted?)
213
- attributes_collection = attributes_collection.to_h
214
- end
210
+ attributes_collection = attributes_collection.to_h if attributes_collection.respond_to?(:permitted?)
215
211
 
216
- unless attributes_collection.is_a?(Hash) || attributes_collection.is_a?(Array)
217
- raise ArgumentError, "Hash or Array expected, got #{attributes_collection.class.name} (#{attributes_collection.inspect})"
218
- end
212
+ raise ArgumentError, "Hash or Array expected, got #{attributes_collection.class.name} (#{attributes_collection.inspect})" unless attributes_collection.is_a?(Hash) || attributes_collection.is_a?(Array)
219
213
 
220
214
  check_record_limit!(options[:limit], attributes_collection)
221
215
 
@@ -242,16 +236,12 @@ module ActiveFedora
242
236
  attributes = attributes.with_indifferent_access
243
237
 
244
238
  if attributes['id'].blank?
245
- unless reject_new_record?(association_name, attributes)
246
- association.build(attributes.except(*UNASSIGNABLE_KEYS))
247
- end
239
+ association.build(attributes.except(*UNASSIGNABLE_KEYS)) unless reject_new_record?(association_name, attributes)
248
240
 
249
241
  elsif existing_record = existing_records.detect { |record| record.id.to_s == attributes['id'].to_s }
250
242
  association.send(:add_record_to_target_with_callbacks, existing_record) if !association.loaded? && !call_reject_if(association_name, attributes)
251
243
 
252
- unless call_reject_if(association_name, attributes)
253
- assign_to_or_mark_for_destruction(existing_record, attributes, options[:allow_destroy])
254
- end
244
+ assign_to_or_mark_for_destruction(existing_record, attributes, options[:allow_destroy]) unless call_reject_if(association_name, attributes)
255
245
 
256
246
  else
257
247
  raise_nested_attributes_record_not_found!(association_name, attributes['id'])
@@ -1,6 +1,8 @@
1
1
  module ActiveFedora
2
2
  class NullLogger < Logger
3
+ # rubocop:disable Lint/MissingSuper
3
4
  def initialize(*); end
5
+ # rubocop:enable Lint/MissingSuper
4
6
 
5
7
  # allows all the usual logger method calls (warn, info, error, etc.)
6
8
  def add(*); end
@@ -1,8 +1,7 @@
1
1
  module ActiveFedora::Orders
2
2
  class ListNode
3
3
  attr_reader :rdf_subject
4
- attr_accessor :prev, :next, :target
5
- attr_writer :next_uri, :prev_uri
4
+ attr_writer :prev, :next, :target, :next_uri, :prev_uri
6
5
  attr_accessor :proxy_in, :proxy_for
7
6
  def initialize(node_cache, rdf_subject, graph = RDF::Repository.new)
8
7
  @rdf_subject = rdf_subject
@@ -120,7 +119,7 @@ module ActiveFedora::Orders
120
119
  end
121
120
 
122
121
  def new_record?
123
- @target && @target.new_record?
122
+ @target&.new_record?
124
123
  end
125
124
 
126
125
  private