active-fedora 9.7.0 → 9.7.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +4 -9
  3. data/History.txt +9 -0
  4. data/lib/active_fedora.rb +2 -2
  5. data/lib/active_fedora/association_hash.rb +2 -2
  6. data/lib/active_fedora/associations/builder/collection_association.rb +1 -1
  7. data/lib/active_fedora/associations/builder/has_many.rb +1 -1
  8. data/lib/active_fedora/associations/collection_association.rb +1 -1
  9. data/lib/active_fedora/associations/collection_proxy.rb +4 -4
  10. data/lib/active_fedora/associations/directly_contains_one_association.rb +3 -7
  11. data/lib/active_fedora/associations/has_many_association.rb +22 -29
  12. data/lib/active_fedora/associations/indirectly_contains_association.rb +1 -1
  13. data/lib/active_fedora/autosave_association.rb +1 -1
  14. data/lib/active_fedora/base.rb +1 -1
  15. data/lib/active_fedora/callbacks.rb +1 -1
  16. data/lib/active_fedora/change_set.rb +1 -2
  17. data/lib/active_fedora/datastreams/nokogiri_datastreams.rb +6 -6
  18. data/lib/active_fedora/file.rb +5 -4
  19. data/lib/active_fedora/file_configurator.rb +6 -11
  20. data/lib/active_fedora/fixity_service.rb +1 -1
  21. data/lib/active_fedora/indexing_service.rb +3 -3
  22. data/lib/active_fedora/ldp_cache.rb +1 -1
  23. data/lib/active_fedora/model.rb +9 -10
  24. data/lib/active_fedora/nested_attributes.rb +1 -1
  25. data/lib/active_fedora/nom_datastream.rb +5 -5
  26. data/lib/active_fedora/om_datastream.rb +2 -2
  27. data/lib/active_fedora/persistence.rb +2 -2
  28. data/lib/active_fedora/qualified_dublin_core_datastream.rb +1 -1
  29. data/lib/active_fedora/rdf/fcrepo.rb +6 -0
  30. data/lib/active_fedora/rdf/persistence.rb +2 -2
  31. data/lib/active_fedora/rdf/rdf_datastream.rb +1 -1
  32. data/lib/active_fedora/reflection.rb +3 -3
  33. data/lib/active_fedora/relation.rb +2 -2
  34. data/lib/active_fedora/solr_query_builder.rb +93 -91
  35. data/lib/active_fedora/solr_service.rb +2 -2
  36. data/lib/active_fedora/version.rb +1 -1
  37. data/lib/active_fedora/versionable.rb +14 -12
  38. data/lib/active_fedora/versions_graph.rb +1 -1
  39. data/spec/integration/full_featured_model_spec.rb +1 -1
  40. data/spec/integration/scoped_query_spec.rb +2 -2
  41. data/spec/integration/versionable_spec.rb +1 -3
  42. data/spec/unit/forbidden_attributes_protection_spec.rb +1 -1
  43. data/spec/unit/ntriples_datastream_spec.rb +1 -1
  44. data/spec/unit/persistence_spec.rb +1 -1
  45. data/spec/unit/predicates_spec.rb +1 -1
  46. data/spec/unit/qualified_dublin_core_datastream_spec.rb +1 -1
  47. data/spec/unit/solr_config_options_spec.rb +3 -3
  48. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 02451c4f7df1542ec57c845259cc21eefd0aff2b
4
- data.tar.gz: a689c5b349b6e55b1e63af345f1e81eac669e51a
3
+ metadata.gz: b84c2ad365e0934c1c9a6900e855dad6e3e0fb89
4
+ data.tar.gz: 138dc99577501a383818150e1e3ce25622312d90
5
5
  SHA512:
6
- metadata.gz: 6e5b2b77aa673793101dfe20d17d7b6b58a8e936d10d5d9bd5d1285f392ada51b25808a89d1dd147dc6827868110d22ce868337b2b078e7ecd20b61ad5d9445f
7
- data.tar.gz: cb38ad07691ed932faa31de89fdc1278b6b8f581e251fd9fd37a84a1fdc9c61b2c5a80eb889c90b3ff85c6553b70941b07e4db680f7ff21df3ee2ab0e778eff7
6
+ metadata.gz: 045396d2d76fc88b5f1ceb99340cb5dfebf6b0af631c13f2ae22d15c5de243758aeaf0717221cb202f310b846b2541f588e941741a081e8f16a71577c214ef76
7
+ data.tar.gz: 42aa7a98b66b0dcc517aa67ec26889b84850bc195d2f7d6b444520f0de9afc890a5144e553906982e6181542a129d616f8d9cfec36bd02f49d8a54d0d84a2a68
@@ -1,7 +1,7 @@
1
1
  require: rubocop-rspec
2
2
 
3
3
  AllCops:
4
- RunRailsCops: true
4
+ TargetRubyVersion: 2.2
5
5
  DisplayCopNames: true
6
6
  Include:
7
7
  - '**/Rakefile'
@@ -9,10 +9,6 @@ AllCops:
9
9
  - 'script/**/*'
10
10
  - 'vendor/**/*'
11
11
 
12
- Lint/RescueException:
13
- Exclude:
14
- - 'lib/active_fedora/ldp_cache.rb'
15
-
16
12
  Lint/HandleExceptions:
17
13
  Exclude:
18
14
  - 'spec/unit/**/*'
@@ -184,9 +180,6 @@ Style/ClassAndModuleChildren:
184
180
  Style/Documentation:
185
181
  Enabled: false
186
182
 
187
- Style/HashSyntax:
188
- Exclude:
189
-
190
183
  Style/GlobalVars:
191
184
  Exclude:
192
185
  - 'spec/**/*'
@@ -210,6 +203,9 @@ Style/FileName:
210
203
  - 'lib/active-fedora.rb'
211
204
  - 'spec/samples/hydra-mods_article_datastream.rb'
212
205
 
206
+ Rails:
207
+ Enabled: true
208
+
213
209
  Rails/Output:
214
210
  Exclude:
215
211
  - 'lib/generators/**/*'
@@ -242,4 +238,3 @@ RSpec/DescribeClass:
242
238
  RSpec/DescribedClass:
243
239
  Exclude:
244
240
  - 'spec/unit/finder_methods_spec.rb'
245
-
@@ -1,3 +1,12 @@
1
+ v9.7.1
2
+ 2016-01-22 : The jcr/mix versionable predicate is no longer used [Adam Wead]
3
+
4
+ 2016-01-22 : Add detail to SolrQueryBuilder.construct_query_for_pids deprecation warning [David Chandek-Stark]
5
+
6
+ 2016-01-21 : Updating to the latest Rubocop [Michael J. Giarlo]
7
+
8
+ 2015-12-04 : Adds :PID property to ActiveFedora::RDF::Fcrepo::Model vocab [David Chandek-Stark]
9
+
1
10
  v9.7.0
2
11
  2015-11-25 : Allowing access to the gone? method from outside the object [Carolyn Cole]
3
12
 
@@ -209,9 +209,9 @@ module ActiveFedora #:nodoc:
209
209
  return config_options[:environment]
210
210
  elsif defined?(Rails.env) && !Rails.env.nil?
211
211
  return Rails.env.to_s
212
- elsif defined?(ENV['environment']) && !(ENV['environment'].nil?)
212
+ elsif defined?(ENV['environment']) && !ENV['environment'].nil?
213
213
  return ENV['environment']
214
- elsif defined?(ENV['RAILS_ENV']) && !(ENV['RAILS_ENV'].nil?)
214
+ elsif defined?(ENV['RAILS_ENV']) && !ENV['RAILS_ENV'].nil?
215
215
  raise "You're depending on RAILS_ENV for setting your environment. Please use ENV['environment'] for non-rails environment setting: 'rake foo:bar environment=test'"
216
216
  else
217
217
  ENV['environment'] = 'development'
@@ -44,8 +44,8 @@ module ActiveFedora
44
44
  def key?(key)
45
45
  keys.include?(key) || keys.map(&:to_s).include?(key)
46
46
  end
47
- alias_method :include?, :key?
48
- alias_method :has_key?, :key?
47
+ alias include? key?
48
+ alias has_key? key?
49
49
 
50
50
  def values
51
51
  keys.map { |k| self[k] }
@@ -1,7 +1,7 @@
1
1
  require 'active_fedora/associations'
2
2
  module ActiveFedora::Associations::Builder
3
3
  class CollectionAssociation < Association #:nodoc:
4
- CALLBACKS = [:before_add, :after_add, :before_remove, :after_remove]
4
+ CALLBACKS = [:before_add, :after_add, :before_remove, :after_remove].freeze
5
5
 
6
6
  self.valid_options += [
7
7
  :before_add, :after_add, :before_remove, :after_remove
@@ -52,7 +52,7 @@ module ActiveFedora::Associations::Builder
52
52
  send(name).delete_all
53
53
  end
54
54
  end
55
- alias_method :define_nullify_dependency_method, :define_delete_all_dependency_method
55
+ alias define_nullify_dependency_method define_delete_all_dependency_method
56
56
 
57
57
  def define_restrict_dependency_method
58
58
  name = self.name
@@ -129,7 +129,7 @@ module ActiveFedora
129
129
  def to_ary
130
130
  load_target.dup
131
131
  end
132
- alias_method :to_a, :to_ary
132
+ alias to_a to_ary
133
133
 
134
134
  def build(attributes = {}, &block)
135
135
  if attributes.is_a?(Array)
@@ -835,7 +835,7 @@ module ActiveFedora
835
835
  @association.include?(record)
836
836
  end
837
837
 
838
- alias_method :new, :build
838
+ alias new build
839
839
 
840
840
  def proxy_association
841
841
  @association
@@ -845,17 +845,17 @@ module ActiveFedora
845
845
  def scope
846
846
  @association.scope
847
847
  end
848
- alias_method :spawn, :scope
848
+ alias spawn scope
849
849
 
850
850
  def to_ary
851
851
  load_target.dup
852
852
  end
853
- alias_method :to_a, :to_ary
853
+ alias to_a to_ary
854
854
 
855
855
  def <<(*records)
856
856
  proxy_association.concat(records) && self
857
857
  end
858
- alias_method :push, :<<
858
+ alias push <<
859
859
 
860
860
  def clear
861
861
  delete_all
@@ -98,13 +98,9 @@ module ActiveFedora
98
98
  # Returns the RDF node that contains metadata like RDF.type assertions for the record
99
99
  # Sometimes this is the record, other times it's record.metadata_node
100
100
  def metadata_node_for_record(record)
101
- if record.respond_to?(:type) && record.respond_to?(:set_value)
102
- return record
103
- elsif record.respond_to?(:metadata_node)
104
- return record.metadata_node
105
- else
106
- raise ArgumentError, "record must either have a metadata node or must respond to .type"
107
- end
101
+ return record if record.respond_to?(:type) && record.respond_to?(:set_value)
102
+ return record.metadata_node if record.respond_to?(:metadata_node)
103
+ raise ArgumentError, "record must either have a metadata node or must respond to .type"
108
104
  end
109
105
  end
110
106
  end
@@ -69,40 +69,33 @@ module ActiveFedora
69
69
 
70
70
  # Deletes the records according to the <tt>:dependent</tt> option.
71
71
  def delete_records(records, method)
72
- if method == :destroy
73
- records.each(&:destroy)
74
- else
75
- # Find all the records that point to this and nullify them
76
- # keys = records.map { |r| r[reflection.association_primary_key] }
77
- # scope = scoped.where(reflection.association_primary_key => keys)
72
+ return records.each(&:destroy) if method == :destroy
73
+ # Find all the records that point to this and nullify them
74
+ # keys = records.map { |r| r[reflection.association_primary_key] }
75
+ # scope = scoped.where(reflection.association_primary_key => keys)
78
76
 
79
- if method == :delete_all
80
- raise "Not Implemented"
81
- # update_counter(-scope.delete_all)
82
- else
77
+ raise "Not Implemented" if method == :delete_all # update_counter(-scope.delete_all)
83
78
 
84
- if reflection.inverse_of # Can't get an inverse when class_name: 'ActiveFedora::Base' is supplied
85
- inverse = reflection.inverse_of
86
- records.each do |record|
87
- next unless record.persisted?
88
- if inverse.collection?
89
- # Remove from a has_and_belongs_to_many
90
- record.association(inverse.name).delete(@owner)
91
- elsif inverse.klass == ActiveFedora::Base
92
- record[inverse.foreign_key] = nil
93
- else
94
- # Remove from a belongs_to
95
- record[reflection.foreign_key] = nil
96
- end
97
- # Check to see if the object still exists (may be already deleted).
98
- # In Rails, they do this with an update_all to avoid callbacks and validations, we may need the same.
99
- record.save! if record.class.exists?(record.id)
100
- end
79
+ if reflection.inverse_of # Can't get an inverse when class_name: 'ActiveFedora::Base' is supplied
80
+ inverse = reflection.inverse_of
81
+ records.each do |record|
82
+ next unless record.persisted?
83
+ if inverse.collection?
84
+ # Remove from a has_and_belongs_to_many
85
+ record.association(inverse.name).delete(@owner)
86
+ elsif inverse.klass == ActiveFedora::Base
87
+ record[inverse.foreign_key] = nil
88
+ else
89
+ # Remove from a belongs_to
90
+ record[reflection.foreign_key] = nil
101
91
  end
102
-
103
- # update_counter(-scope.update_all(reflection.foreign_key => nil))
92
+ # Check to see if the object still exists (may be already deleted).
93
+ # In Rails, they do this with an update_all to avoid callbacks and validations, we may need the same.
94
+ record.save! if record.class.exists?(record.id)
104
95
  end
105
96
  end
97
+
98
+ # update_counter(-scope.update_all(reflection.foreign_key => nil))
106
99
  end
107
100
  end
108
101
  end
@@ -30,7 +30,7 @@ module ActiveFedora
30
30
  target.map(&:id)
31
31
  else
32
32
  owner.resource.query(predicate: predicate)
33
- .map { |s| ActiveFedora::Base.uri_to_id(s.object) } | target.map(&:id)
33
+ .map { |s| ActiveFedora::Base.uri_to_id(s.object) } | target.map(&:id)
34
34
  end
35
35
  end
36
36
 
@@ -75,7 +75,7 @@ module ActiveFedora
75
75
  module AutosaveAssociation
76
76
  extend ActiveSupport::Concern
77
77
 
78
- ASSOCIATION_TYPES = %w( HasMany BelongsTo HasAndBelongsToMany DirectlyContains IndirectlyContains)
78
+ ASSOCIATION_TYPES = %w( HasMany BelongsTo HasAndBelongsToMany DirectlyContains IndirectlyContains).freeze
79
79
 
80
80
  module AssociationBuilderExtension #:nodoc:
81
81
  def self.included(base)
@@ -1,4 +1,4 @@
1
- SOLR_DOCUMENT_ID = "id" unless defined?(SOLR_DOCUMENT_ID) && !SOLR_DOCUMENT_ID.nil?
1
+ SOLR_DOCUMENT_ID = "id".freeze unless defined?(SOLR_DOCUMENT_ID) && !SOLR_DOCUMENT_ID.nil?
2
2
  ENABLE_SOLR_UPDATES = true unless defined?(ENABLE_SOLR_UPDATES)
3
3
  require 'active_support/descendants_tracker'
4
4
  require 'active_fedora/errors'
@@ -216,7 +216,7 @@ module ActiveFedora
216
216
  :before_save, :around_save, :after_save, :before_create, :around_create,
217
217
  :after_create, :before_update, :around_update, :after_update,
218
218
  :before_destroy, :around_destroy, :after_destroy
219
- ]
219
+ ].freeze
220
220
 
221
221
  included do
222
222
  extend ActiveModel::Callbacks
@@ -59,8 +59,7 @@ module ActiveFedora
59
59
  end
60
60
 
61
61
  def internal?
62
- value.object.to_s.start_with?("http://www.jcp.org") ||
63
- value.object.to_s.start_with?("http://fedora.info") ||
62
+ value.object.to_s.start_with?("http://www.jcp.org", "http://fedora.info") ||
64
63
  value.predicate.to_s.start_with?("http://fedora.info")
65
64
  end
66
65
  end
@@ -15,12 +15,12 @@ module ActiveFedora
15
15
 
16
16
  def ng_xml
17
17
  @ng_xml ||= begin
18
- if new_record?
19
- ## Load up the template
20
- xml = self.class.xml_template
21
- else
22
- xml = Nokogiri::XML::Document.parse(remote_content)
23
- end
18
+ xml = if new_record?
19
+ ## Load up the template
20
+ self.class.xml_template
21
+ else
22
+ Nokogiri::XML::Document.parse(remote_content)
23
+ end
24
24
  self.class.decorate_ng_xml xml
25
25
  end
26
26
  end
@@ -188,6 +188,11 @@ module ActiveFedora
188
188
  false
189
189
  end
190
190
 
191
+ def self.relation
192
+ FileRelation.new(self)
193
+ end
194
+ private_class_method :relation
195
+
191
196
  protected
192
197
 
193
198
  # The string to prefix all solr fields with. Override this method if you want
@@ -198,10 +203,6 @@ module ActiveFedora
198
203
 
199
204
  private
200
205
 
201
- def self.relation
202
- FileRelation.new(self)
203
- end
204
-
205
206
  # Rack::Test::UploadedFile is often set via content=, however it's not an IO, though it wraps an io object.
206
207
  def behaves_like_io?(obj)
207
208
  [IO, Tempfile, StringIO].any? { |klass| obj.is_a? klass } || (defined?(Rack) && obj.is_a?(Rack::Test::UploadedFile))
@@ -149,14 +149,12 @@ module ActiveFedora
149
149
  # Given the solr_config that's been loaded for this environment,
150
150
  # determine which solr url to use
151
151
  def solr_url(solr_config)
152
+ return solr_config[:url] if solr_config.key?(:url)
153
+ return solr_config['url'] if solr_config.key?('url')
152
154
  if @index_full_text == true && solr_config.key?(:fulltext) && solr_config[:fulltext].key?('url')
153
- return solr_config[:fulltext]['url']
155
+ solr_config[:fulltext]['url']
154
156
  elsif solr_config.key?(:default) && solr_config[:default].key?('url')
155
- return solr_config[:default]['url']
156
- elsif solr_config.key?('url')
157
- return solr_config['url']
158
- elsif solr_config.key?(:url)
159
- return solr_config[:url]
157
+ solr_config[:default]['url']
160
158
  else
161
159
  raise URI::InvalidURIError
162
160
  end
@@ -208,11 +206,8 @@ module ActiveFedora
208
206
  # Checks the existing fedora_config.path to see if there is a solr.yml there
209
207
  def check_fedora_path_for_solr
210
208
  path = ::File.dirname(self.path) + "/solr.yml"
211
- if ::File.file? path
212
- return path
213
- else
214
- return nil
215
- end
209
+ return unless ::File.file? path
210
+ path
216
211
  end
217
212
 
218
213
  def predicate_config
@@ -52,7 +52,7 @@ module ActiveFedora
52
52
  # See https://jira.duraspace.org/browse/FCREPO-1247
53
53
  # @param [String] uri
54
54
  def encoded_url(uri)
55
- if uri.match("fcr:versions")
55
+ if uri =~ /fcr:versions/
56
56
  uri.gsub(/fcr:versions/, "fcr%3aversions")
57
57
  else
58
58
  uri
@@ -39,9 +39,9 @@ module ActiveFedora
39
39
  Solrizer.set_field(solr_doc, 'system_create', c_time, :stored_sortable)
40
40
  Solrizer.set_field(solr_doc, 'system_modified', m_time, :stored_sortable)
41
41
  Solrizer.set_field(solr_doc, 'active_fedora_model', object.class.inspect, :stored_sortable)
42
- solr_doc.merge!(QueryResultBuilder::HAS_MODEL_SOLR_FIELD => object.has_model)
43
- solr_doc.merge!(SOLR_DOCUMENT_ID.to_sym => object.id)
44
- solr_doc.merge!(self.class.profile_solr_name => profile_service.new(object).export)
42
+ solr_doc[QueryResultBuilder::HAS_MODEL_SOLR_FIELD] = object.has_model
43
+ solr_doc[SOLR_DOCUMENT_ID.to_sym] = object.id
44
+ solr_doc[self.class.profile_solr_name] = profile_service.new(object).export
45
45
  object.declared_attached_files.each do |name, file|
46
46
  solr_doc.merge! file.to_solr(solr_doc, name: name.to_s)
47
47
  end
@@ -29,7 +29,7 @@ module ActiveFedora
29
29
  end
30
30
 
31
31
  response
32
- rescue Exception => e
32
+ rescue StandardError => e
33
33
  reset_cache_settings
34
34
  raise e
35
35
  end
@@ -1,4 +1,4 @@
1
- SOLR_DOCUMENT_ID = "id" unless defined?(SOLR_DOCUMENT_ID)
1
+ SOLR_DOCUMENT_ID = "id".freeze unless defined?(SOLR_DOCUMENT_ID)
2
2
 
3
3
  module ActiveFedora
4
4
  # = ActiveFedora
@@ -17,14 +17,13 @@ module ActiveFedora
17
17
  ActiveFedora.class_from_string(model_value)
18
18
  end
19
19
 
20
- private
21
-
22
- def self.class_exists?(class_name)
23
- return false if class_name.empty?
24
- klass = class_name.constantize
25
- return klass.is_a?(Class)
26
- rescue NameError
27
- return false
28
- end
20
+ def self.class_exists?(class_name)
21
+ return false if class_name.empty?
22
+ klass = class_name.constantize
23
+ return klass.is_a?(Class)
24
+ rescue NameError
25
+ return false
26
+ end
27
+ private_class_method :class_exists?
29
28
  end
30
29
  end
@@ -113,7 +113,7 @@ module ActiveFedora
113
113
 
114
114
  # Attribute hash keys that should not be assigned as normal attributes.
115
115
  # These hash keys are nested attributes implementation details.
116
- UNASSIGNABLE_KEYS = %w( id _destroy )
116
+ UNASSIGNABLE_KEYS = %w( id _destroy ).freeze
117
117
 
118
118
  def assign_nested_attributes_for_collection_association(association_name, attributes_collection)
119
119
  options = nested_attributes_options[association_name]
@@ -34,11 +34,11 @@ module ActiveFedora
34
34
  term.values.each do |v|
35
35
  Array(term.options[:index]).each do |index_as|
36
36
  solr_doc[index_as] ||= []
37
- if v.is_a? Nokogiri::XML::Node
38
- solr_doc[index_as] << v.text
39
- else
40
- solr_doc[index_as] << v
41
- end
37
+ solr_doc[index_as] << if v.is_a? Nokogiri::XML::Node
38
+ v.text
39
+ else
40
+ v
41
+ end
42
42
  end
43
43
  end
44
44
  end
@@ -13,8 +13,8 @@ module ActiveFedora
13
13
  include OM::XML::TerminologyBasedSolrizer # this adds support for calling .to_solr
14
14
  include Datastreams::NokogiriDatastreams
15
15
 
16
- alias_method(:om_term_values, :term_values) unless method_defined?(:om_term_values)
17
- alias_method(:om_update_values, :update_values) unless method_defined?(:om_update_values)
16
+ alias om_term_values term_values unless method_defined?(:om_term_values)
17
+ alias om_update_values update_values unless method_defined?(:om_update_values)
18
18
 
19
19
  def default_mime_type
20
20
  'text/xml'
@@ -37,7 +37,7 @@ module ActiveFedora
37
37
  save
38
38
  end
39
39
 
40
- alias_method :update_attributes, :update
40
+ alias update_attributes update
41
41
 
42
42
  # Deletes an object from Fedora and deletes the indexed record from Solr.
43
43
  # Delete does not run any callbacks, so consider using _destroy_ instead.
@@ -186,7 +186,7 @@ module ActiveFedora
186
186
  end
187
187
 
188
188
  def base_path_for_resource
189
- init_root_path if self.has_uri_prefix?
189
+ init_root_path if has_uri_prefix?
190
190
  root_resource_path
191
191
  end
192
192
 
@@ -76,7 +76,7 @@ module ActiveFedora
76
76
  :title,
77
77
  :type,
78
78
  :valid
79
- ] # removed :format
79
+ ].freeze # removed :format
80
80
  DCTERMS.freeze
81
81
 
82
82
  # Constructor. this class will call self.field for each DCTERM. In short, all DCTERMS fields will already exist
@@ -157,6 +157,12 @@ module ActiveFedora::RDF
157
157
  comment: %(indicates the owner of an object).freeze,
158
158
  label: "ownerId".freeze,
159
159
  type: "rdf:Property".freeze
160
+ property :PID,
161
+ comment: %(the Fedora 3 PID for an object).freeze,
162
+ label: "PID".freeze,
163
+ domain: "info:fedora/fedora-system:def/model#FedoraObject".freeze,
164
+ range: "xsd:string".freeze,
165
+ type: "rdf:Property".freeze
160
166
  property :state,
161
167
  comment: %(indicates the state of the object or datastream).freeze,
162
168
  label: "state".freeze,
@@ -10,7 +10,7 @@ module ActiveFedora
10
10
  module Persistence
11
11
  extend ActiveSupport::Concern
12
12
 
13
- BASE_URI = 'info:fedora/'
13
+ BASE_URI = 'info:fedora/'.freeze
14
14
 
15
15
  included do
16
16
  configure base_uri: BASE_URI unless base_uri
@@ -25,7 +25,7 @@ module ActiveFedora
25
25
 
26
26
  # Overrides ActiveTriples::Resource
27
27
  def persisted?
28
- @persisted ||= (!datastream.new_record?)
28
+ @persisted ||= !datastream.new_record?
29
29
  end
30
30
  end
31
31
  end
@@ -122,7 +122,7 @@ module ActiveFedora
122
122
  end
123
123
  end
124
124
 
125
- alias_method :graph, :resource
125
+ alias graph resource
126
126
 
127
127
  def refresh_attributes
128
128
  @resource = nil
@@ -217,7 +217,7 @@ module ActiveFedora
217
217
  [self]
218
218
  end
219
219
 
220
- alias_method :source_macro, :macro
220
+ alias source_macro macro
221
221
 
222
222
  def has_inverse?
223
223
  inverse_name
@@ -265,8 +265,8 @@ module ActiveFedora
265
265
  end
266
266
  end
267
267
 
268
- VALID_AUTOMATIC_INVERSE_MACROS = [:has_many, :has_and_belongs_to_many, :belongs_to]
269
- INVALID_AUTOMATIC_INVERSE_OPTIONS = [:conditions, :through, :polymorphic, :foreign_key]
268
+ VALID_AUTOMATIC_INVERSE_MACROS = [:has_many, :has_and_belongs_to_many, :belongs_to].freeze
269
+ INVALID_AUTOMATIC_INVERSE_OPTIONS = [:conditions, :through, :polymorphic, :foreign_key].freeze
270
270
 
271
271
  private
272
272
 
@@ -5,7 +5,7 @@ module ActiveFedora
5
5
 
6
6
  attr_reader :loaded
7
7
  attr_accessor :default_scoped
8
- alias_method :loaded?, :loaded
8
+ alias loaded? loaded
9
9
 
10
10
  attr_accessor :values, :klass
11
11
 
@@ -129,7 +129,7 @@ module ActiveFedora
129
129
 
130
130
  private
131
131
 
132
- VALID_FIND_OPTIONS = [:order, :limit, :start, :conditions, :cast]
132
+ VALID_FIND_OPTIONS = [:order, :limit, :start, :conditions, :cast].freeze
133
133
 
134
134
  def apply_finder_options(options)
135
135
  relation = clone
@@ -2,114 +2,116 @@ module ActiveFedora
2
2
  module SolrQueryBuilder
3
3
  PARSED_SUFFIX = '_tesim'.freeze
4
4
 
5
- # Construct a solr query for a list of ids
6
- # This is used to get a solr response based on the list of ids in an object's RELS-EXT relationhsips
7
- # If the id_array is empty, defaults to a query of "id:NEVER_USE_THIS_ID", which will return an empty solr response
8
- # @param [Array] id_array the ids that you want included in the query
9
- def self.construct_query_for_ids(id_array)
10
- ids = id_array.reject(&:blank?)
11
- return "id:NEVER_USE_THIS_ID" if ids.empty?
12
- "{!terms f=#{SOLR_DOCUMENT_ID}}#{ids.join(',')}"
13
- end
5
+ class << self
6
+ # Construct a solr query for a list of ids
7
+ # This is used to get a solr response based on the list of ids in an object's RELS-EXT relationhsips
8
+ # If the id_array is empty, defaults to a query of "id:NEVER_USE_THIS_ID", which will return an empty solr response
9
+ # @param [Array] id_array the ids that you want included in the query
10
+ def construct_query_for_ids(id_array)
11
+ ids = id_array.reject(&:blank?)
12
+ return "id:NEVER_USE_THIS_ID" if ids.empty?
13
+ "{!terms f=#{SOLR_DOCUMENT_ID}}#{ids.join(',')}"
14
+ end
14
15
 
15
- # Create a raw query clause suitable for sending to solr as an fq element
16
- # @param [String] key
17
- # @param [String] value
18
- def self.raw_query(key, value)
19
- "_query_:\"{!raw f=#{key}}#{value.gsub('"', '\"')}\""
20
- end
16
+ # Create a raw query clause suitable for sending to solr as an fq element
17
+ # @param [String] key
18
+ # @param [String] value
19
+ def raw_query(key, value)
20
+ "_query_:\"{!raw f=#{key}}#{value.gsub('"', '\"')}\""
21
+ end
21
22
 
22
- def self.solr_name(*args)
23
- Solrizer.default_field_mapper.solr_name(*args)
24
- end
23
+ def solr_name(*args)
24
+ Solrizer.default_field_mapper.solr_name(*args)
25
+ end
25
26
 
26
- # Create a query with a clause for each key, value
27
- # @param [Hash, Array<Array<String>>] field_pairs key is the predicate, value is the target_uri
28
- # @param [String] join_with ('AND') the value we're joining the clauses with
29
- # @example
30
- # construct_query_for_rel [[:has_model, "info:fedora/afmodel:ComplexCollection"], [:has_model, "info:fedora/afmodel:ActiveFedora_Base"]], 'OR'
31
- # # => _query_:"{!raw f=has_model_ssim}info:fedora/afmodel:ComplexCollection" OR _query_:"{!raw f=has_model_ssim}info:fedora/afmodel:ActiveFedora_Base"
32
- #
33
- # construct_query_for_rel [[Book.reflect_on_association(:library), "foo/bar/baz"]]
34
- def self.construct_query_for_rel(field_pairs, join_with = ' AND ')
35
- field_pairs = field_pairs.to_a if field_pairs.is_a? Hash
36
- construct_query(property_values_to_solr(field_pairs), join_with)
37
- end
27
+ # Create a query with a clause for each key, value
28
+ # @param [Hash, Array<Array<String>>] field_pairs key is the predicate, value is the target_uri
29
+ # @param [String] join_with ('AND') the value we're joining the clauses with
30
+ # @example
31
+ # construct_query_for_rel [[:has_model, "info:fedora/afmodel:ComplexCollection"], [:has_model, "info:fedora/afmodel:ActiveFedora_Base"]], 'OR'
32
+ # # => _query_:"{!raw f=has_model_ssim}info:fedora/afmodel:ComplexCollection" OR _query_:"{!raw f=has_model_ssim}info:fedora/afmodel:ActiveFedora_Base"
33
+ #
34
+ # construct_query_for_rel [[Book.reflect_on_association(:library), "foo/bar/baz"]]
35
+ def construct_query_for_rel(field_pairs, join_with = ' AND ')
36
+ field_pairs = field_pairs.to_a if field_pairs.is_a? Hash
37
+ construct_query(property_values_to_solr(field_pairs), join_with)
38
+ end
38
39
 
39
- # Construct a solr query from a list of pairs (e.g. [field name, values])
40
- # @param [Array<Array>] field_pairs a list of pairs of property name and values
41
- # @param [String] join_with ('AND') the value we're joining the clauses with
42
- # @return [String] a solr query
43
- # @example
44
- # construct_query([['library_id_ssim', '123'], ['owner_ssim', 'Fred']])
45
- # # => "_query_:\"{!raw f=library_id_ssim}123\" AND _query_:\"{!raw f=owner_ssim}Fred\""
46
- def self.construct_query(field_pairs, join_with = ' AND ')
47
- pairs_to_clauses(field_pairs).join(join_with)
48
- end
40
+ # Construct a solr query from a list of pairs (e.g. [field name, values])
41
+ # @param [Array<Array>] field_pairs a list of pairs of property name and values
42
+ # @param [String] join_with ('AND') the value we're joining the clauses with
43
+ # @return [String] a solr query
44
+ # @example
45
+ # construct_query([['library_id_ssim', '123'], ['owner_ssim', 'Fred']])
46
+ # # => "_query_:\"{!raw f=library_id_ssim}123\" AND _query_:\"{!raw f=owner_ssim}Fred\""
47
+ def construct_query(field_pairs, join_with = ' AND ')
48
+ pairs_to_clauses(field_pairs).join(join_with)
49
+ end
49
50
 
50
- private
51
+ private
51
52
 
52
- # @param [Array<Array>] pairs a list of (key, value) pairs. The value itself may
53
- # @return [Array] a list of solr clauses
54
- def self.pairs_to_clauses(pairs)
55
- pairs.flat_map do |field, value|
56
- condition_to_clauses(field, value)
53
+ # @param [Array<Array>] pairs a list of (key, value) pairs. The value itself may
54
+ # @return [Array] a list of solr clauses
55
+ def pairs_to_clauses(pairs)
56
+ pairs.flat_map do |field, value|
57
+ condition_to_clauses(field, value)
58
+ end
57
59
  end
58
- end
59
60
 
60
- # @param [String] field
61
- # @param [String, Array<String>] values
62
- # @return [Array<String>]
63
- def self.condition_to_clauses(field, values)
64
- values = Array(values)
65
- values << nil if values.empty?
66
- values.map do |value|
67
- if value.present?
68
- if parsed?(field)
69
- # If you do a raw query on a parsed field you won't get the matches you expect.
70
- "#{field}:#{solr_escape(value)}"
61
+ # @param [String] field
62
+ # @param [String, Array<String>] values
63
+ # @return [Array<String>]
64
+ def condition_to_clauses(field, values)
65
+ values = Array(values)
66
+ values << nil if values.empty?
67
+ values.map do |value|
68
+ if value.present?
69
+ if parsed?(field)
70
+ # If you do a raw query on a parsed field you won't get the matches you expect.
71
+ "#{field}:#{solr_escape(value)}"
72
+ else
73
+ raw_query(field, value)
74
+ end
71
75
  else
72
- raw_query(field, value)
76
+ # Check that the field is not present. In SQL: "WHERE field IS NULL"
77
+ "-#{field}:[* TO *]"
73
78
  end
74
- else
75
- # Check that the field is not present. In SQL: "WHERE field IS NULL"
76
- "-#{field}:[* TO *]"
77
79
  end
78
80
  end
79
- end
80
81
 
81
- def self.parsed?(field)
82
- field.end_with?(PARSED_SUFFIX)
83
- end
82
+ def parsed?(field)
83
+ field.end_with?(PARSED_SUFFIX)
84
+ end
84
85
 
85
- # Adds esaping for spaces which are not handled by RSolr.solr_escape
86
- # See rsolr/rsolr#101
87
- def self.solr_escape(terms)
88
- RSolr.solr_escape(terms).gsub(/\s+/, "\\ ")
89
- end
86
+ # Adds esaping for spaces which are not handled by RSolr.solr_escape
87
+ # See rsolr/rsolr#101
88
+ def solr_escape(terms)
89
+ RSolr.solr_escape(terms).gsub(/\s+/, "\\ ")
90
+ end
90
91
 
91
- # Given a list of pairs (e.g. [field name, values]), convert the field names
92
- # to solr names
93
- # @param [Array<Array>] pairs a list of pairs of property name and values
94
- # @return [Hash] map of solr fields to values
95
- # @example
96
- # property_values_to_solr([['library_id', '123'], ['owner', 'Fred']])
97
- # # => [['library_id_ssim', '123'], ['owner_ssim', 'Fred']]
98
- def self.property_values_to_solr(pairs)
99
- pairs.each_with_object([]) do |(property, value), list|
100
- list << [solr_field(property), value]
92
+ # Given a list of pairs (e.g. [field name, values]), convert the field names
93
+ # to solr names
94
+ # @param [Array<Array>] pairs a list of pairs of property name and values
95
+ # @return [Hash] map of solr fields to values
96
+ # @example
97
+ # property_values_to_solr([['library_id', '123'], ['owner', 'Fred']])
98
+ # # => [['library_id_ssim', '123'], ['owner_ssim', 'Fred']]
99
+ def property_values_to_solr(pairs)
100
+ pairs.each_with_object([]) do |(property, value), list|
101
+ list << [solr_field(property), value]
102
+ end
101
103
  end
102
- end
103
104
 
104
- # @param [String, ActiveFedora::Relation] field
105
- # @return [String] the corresponding solr field for the string
106
- def self.solr_field(field)
107
- case field
108
- when ActiveFedora::Reflection::AssociationReflection
109
- field.solr_key
110
- else
111
- solr_name(field, :symbol)
105
+ # @param [String, ActiveFedora::Relation] field
106
+ # @return [String] the corresponding solr field for the string
107
+ def solr_field(field)
108
+ case field
109
+ when ActiveFedora::Reflection::AssociationReflection
110
+ field.solr_key
111
+ else
112
+ solr_name(field, :symbol)
113
+ end
112
114
  end
113
- end
115
+ end
114
116
  end
115
117
  end
@@ -10,7 +10,7 @@ module ActiveFedora
10
10
  def initialize(host, args)
11
11
  host = 'http://localhost:8080/solr' unless host
12
12
  args = { read_timeout: 120, open_timeout: 120 }.merge(args.dup)
13
- args.merge!(url: host)
13
+ args[:url] = host
14
14
  @conn = RSolr.connect args
15
15
  end
16
16
 
@@ -71,7 +71,7 @@ module ActiveFedora
71
71
  end
72
72
 
73
73
  def construct_query_for_pids(id_array)
74
- Deprecation.warn SolrService, "construct_query_for_pids is deprecated and will be removed in active-fedora 10.0"
74
+ Deprecation.warn SolrService, "SolrService.construct_query_for_pids is deprecated. Use SolrQueryBuilder.construct_query_for_ids instead. This will be removed in active-fedora 10.0"
75
75
  SolrQueryBuilder.construct_query_for_ids(id_array)
76
76
  end
77
77
 
@@ -1,3 +1,3 @@
1
1
  module ActiveFedora
2
- VERSION = "9.7.0"
2
+ VERSION = "9.7.1".freeze
3
3
  end
@@ -15,7 +15,7 @@ module ActiveFedora
15
15
  end
16
16
 
17
17
  def model_type
18
- if self.respond_to?(:metadata)
18
+ if respond_to?(:metadata)
19
19
  metadata.ldp_source.graph.query(predicate: ::RDF.type).objects
20
20
  else
21
21
  resource.query(subject: resource.rdf_subject, predicate: ::RDF.type).objects
@@ -50,23 +50,17 @@ module ActiveFedora
50
50
  resp = ActiveFedora.fedora.connection.patch(versions.with_label(label).uri, nil)
51
51
  @versions = nil
52
52
  reload
53
- refresh_attributes if self.respond_to?("refresh_attributes")
53
+ refresh_attributes if respond_to?("refresh_attributes")
54
54
  resp.success?
55
55
  end
56
56
 
57
57
  private
58
58
 
59
59
  def versions_request
60
- resp = begin
61
- ActiveFedora.fedora.connection.get(versions_uri)
62
- rescue Ldp::NotFound
63
- return ''
64
- end
65
- if !resp.success?
66
- raise "unexpected return value #{resp.status} for when getting datastream content at #{uri}\n\t#{resp.body}"
67
- elsif resp.headers['content-type'] != 'text/turtle'
68
- raise "unknown response format. got '#{resp.headers['content-type']}', but was expecting 'text/turtle'"
69
- end
60
+ return '' unless has_versions?
61
+ resp = ActiveFedora.fedora.connection.get(versions_uri)
62
+ raise ActiveFedoraError, status_message(resp) unless resp.success?
63
+ raise ActiveFedoraError, bad_headers(resp) unless resp.headers['content-type'] == 'text/turtle'
70
64
  resp.body
71
65
  end
72
66
 
@@ -81,5 +75,13 @@ module ActiveFedora
81
75
  "version" + (versions.all.count + 1).to_s
82
76
  end
83
77
  end
78
+
79
+ def status_message(response)
80
+ "Unexpected return value #{response.status} when retrieving datastream content at #{uri}\n\t#{response.body}"
81
+ end
82
+
83
+ def bad_headers(response)
84
+ "Unknown response format. Got '#{response.headers['content-type']}', but was expecting 'text/turtle'"
85
+ end
84
86
  end
85
87
  end
@@ -3,7 +3,7 @@ module ActiveFedora
3
3
  def all(opts = {})
4
4
  versions = fedora_versions
5
5
  unless opts[:include_auto_save]
6
- versions.reject! { |version| version.label.match("auto") }
6
+ versions.reject! { |version| version.label =~ /auto/ }
7
7
  end
8
8
  versions.sort_by { |version| DateTime.parse(version.created) }
9
9
  rescue ArgumentError, NoMethodError
@@ -140,7 +140,7 @@ describe ActiveFedora::Base do
140
140
 
141
141
  @dublin_core_sample_values.each_pair do |field, value|
142
142
  next if [:format, :type].include?(field) # format and type are methods declared on Object
143
- expect(dublin_core_ds.send("#{field}")).to eq [value]
143
+ expect(dublin_core_ds.send(field.to_s)).to eq [value]
144
144
  end
145
145
  end
146
146
 
@@ -40,7 +40,7 @@ describe ActiveFedora::Querying do
40
40
  expect(result).to be_instance_of(Array)
41
41
  # this test is meaningless if the array length is zero
42
42
  expect(result.length > 0).to be true
43
- expect(result).to all(be_an ModelIntegrationSpec::Basic)
43
+ expect(result).to all(be_an(ModelIntegrationSpec::Basic))
44
44
  end
45
45
  end
46
46
 
@@ -90,7 +90,7 @@ describe ActiveFedora::Querying do
90
90
  first_condition = { ActiveFedora::SolrQueryBuilder.solr_name('bar', type: :string) => 'Peanuts' }
91
91
  second_condition = "foo_tesim:bar"
92
92
  where_values = ModelIntegrationSpec::Basic.where(first_condition)
93
- .where(second_condition).where_values
93
+ .where(second_condition).where_values
94
94
  expect(where_values).to eq ["bar_tesim:Peanuts",
95
95
  "(foo_tesim:bar)"]
96
96
  end
@@ -75,9 +75,7 @@ describe ActiveFedora::Versionable do
75
75
  subject.create_version
76
76
  end
77
77
 
78
- it "sets model_type to versionable" do
79
- expect(subject.reload.model_type).to include ::RDF::URI.new('http://www.jcp.org/jcr/mix/1.0versionable')
80
- end
78
+ it { is_expected.to have_versions }
81
79
 
82
80
  it "has one version" do
83
81
  expect(subject.versions).to be_kind_of ActiveFedora::VersionsGraph
@@ -4,7 +4,7 @@ describe ActiveFedora::Attributes, ".new" do
4
4
  before(:all) do
5
5
  class ProtectedParams < ActiveSupport::HashWithIndifferentAccess
6
6
  attr_accessor :permitted
7
- alias_method :permitted?, :permitted
7
+ alias permitted? permitted
8
8
 
9
9
  def initialize(attributes)
10
10
  super(attributes)
@@ -12,7 +12,7 @@ describe ActiveFedora::NtriplesRDFDatastream do
12
12
  property :based_near, predicate: ::RDF::FOAF.based_near
13
13
  property :related_url, predicate: ::RDF::RDFS.seeAlso
14
14
  end
15
- @subject = MyDatastream.new(ActiveFedora::Base.id_to_uri '/test:1/descMetadata')
15
+ @subject = MyDatastream.new(ActiveFedora::Base.id_to_uri('/test:1/descMetadata'))
16
16
  @subject.content = File.new('spec/fixtures/mixed_rdf_descMetadata.nt').read
17
17
  end
18
18
  after do
@@ -19,7 +19,7 @@ describe ActiveFedora::Persistence do
19
19
  context 'when a block is provided' do
20
20
  it 'passes the block to initialize' do
21
21
  expect_any_instance_of(ActiveFedora::Base).to receive(:save)
22
- expect { |b| ActiveFedora::Base.create(&b) }.to yield_with_args(an_instance_of ActiveFedora::Base)
22
+ expect { |b| ActiveFedora::Base.create(&b) }.to yield_with_args(an_instance_of(ActiveFedora::Base))
23
23
  end
24
24
  end
25
25
  end
@@ -77,7 +77,7 @@ describe ActiveFedora::Predicates do
77
77
  expect(described_class.predicate_lookup(:is_part_of)).to eq "isPartOf"
78
78
  expect(described_class.predicate_lookup(:is_member_of)).to eq "isMemberOf"
79
79
  expect(described_class.predicate_lookup("isPartOfCollection")).to eq "isPartOfCollection"
80
- described_class.predicate_config[:predicate_mapping].merge!("some_namespace" => { has_foo: "hasFOO" })
80
+ described_class.predicate_config[:predicate_mapping]["some_namespace"] = { has_foo: "hasFOO" }
81
81
  expect(described_class.find_predicate(:has_foo)).to eq ["hasFOO", "some_namespace"]
82
82
  expect(described_class.predicate_lookup(:has_foo, "some_namespace")).to eq "hasFOO"
83
83
  expect(lambda { described_class.predicate_lookup(:has_foo) }).to raise_error ActiveFedora::UnregisteredPredicateError
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe ActiveFedora::QualifiedDublinCoreDatastream do
4
- DC_ELEMENTS = [:contributor, :coverage, :creator, :date, :description, :identifier, :language, :publisher, :relation, :rights, :source]
4
+ DC_ELEMENTS = [:contributor, :coverage, :creator, :date, :description, :identifier, :language, :publisher, :relation, :rights, :source].freeze
5
5
 
6
6
  let(:sample_xml) do "<dc xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:dcterms='http://purl.org/dc/terms/'>
7
7
  <dcterms:type xsi:type='DCMITYPE'>sound</dcterms:type>
@@ -14,14 +14,14 @@ describe ActiveFedora do
14
14
 
15
15
  describe "SOLR_DOCUMENT_ID" do
16
16
  before(:all) do
17
- SOLR_DOCUMENT_ID = "MY_SAMPLE_ID"
17
+ SOLR_DOCUMENT_ID = "MY_SAMPLE_ID".freeze
18
18
  end
19
19
  after(:all) do
20
- SOLR_DOCUMENT_ID = "id"
20
+ SOLR_DOCUMENT_ID = "id".freeze
21
21
  end
22
22
  it "is used by ActiveFedora::Base.to_solr" do
23
23
  allow(@test_object).to receive(:id).and_return('changeme:123')
24
- SOLR_DOCUMENT_ID = "MY_SAMPLE_ID"
24
+ SOLR_DOCUMENT_ID = "MY_SAMPLE_ID".freeze
25
25
  expect(@test_object.to_solr[SOLR_DOCUMENT_ID.to_sym]).to eq 'changeme:123'
26
26
  expect(@test_object.to_solr[:id]).to be_nil
27
27
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active-fedora
3
3
  version: !ruby/object:Gem::Version
4
- version: 9.7.0
4
+ version: 9.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Zumwalt
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2015-11-30 00:00:00.000000000 Z
13
+ date: 2016-01-29 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rsolr
@@ -638,7 +638,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
638
638
  version: '0'
639
639
  requirements: []
640
640
  rubyforge_project:
641
- rubygems_version: 2.4.8
641
+ rubygems_version: 2.5.1
642
642
  signing_key:
643
643
  specification_version: 4
644
644
  summary: A convenience libary for manipulating documents in the Fedora Repository.