Skip to content

Commit

Permalink
Merge 0bd1af0 into e9c8697
Browse files Browse the repository at this point in the history
  • Loading branch information
atz committed Sep 28, 2018
2 parents e9c8697 + 0bd1af0 commit 8a1911b
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 21 deletions.
5 changes: 3 additions & 2 deletions app/lib/pre_assembly/bundle.rb
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,10 @@ def all_object_files
digital_objects.map(&:object_files).flatten
end

# @return [PreAssembly::ObjectFile]
def new_object_file(stageable, file_path)
ObjectFile.new(
path: file_path,
file_path,
relative_path: relative_path(get_base_dir(stageable), file_path),
exclude_from_content: exclude_from_content(file_path)
)
Expand All @@ -163,7 +164,7 @@ def exclude_from_content(file_path)
# sets the checksum attribute.
def load_checksums(dobj)
log ' - load_checksums()'
dobj.object_files.each { |file| file.checksum = file.md5 }
dobj.object_files.each { |file| file.provider_md5 = file.md5 }
end

# confirm that the all of the source IDs supplied within a manifest are locally unique
Expand Down
26 changes: 13 additions & 13 deletions app/lib/pre_assembly/object_file.rb
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
module PreAssembly
class ObjectFile < Assembly::ObjectFile
attr_accessor :relative_path, :exclude_from_content
attr_reader :checksum
include ActiveModel::AttributeMethods
attr_accessor :exclude_from_content
alias_attribute :checksum, :provider_md5

def initialize(params = {})
@path = params[:path]
@relative_path = params[:relative_path]
self.checksum = params[:checksum]
@exclude_from_content = params[:exclude_from_content]
end

def checksum=(value)
@checksum = value
self.provider_md5 = value # this is an attribute of the Assembly::ObjectFile class
# @param [String] path full path
# @param [Hash<Symbol => Object>] params
# @see Assembly::ObjectFile, Assembly::ObjectFileable
def initialize(path, params = {})
super
@provider_md5 ||= params[:checksum]
@exclude_from_content = params[:exclude_from_content] || false
end

# This is a bit of a lie. ObjectFiles with the same relative_path but different checksums
# are clearly not representing the same thing.
def <=>(other)
@relative_path <=> other.relative_path
relative_path <=> other.relative_path
end
end
end
9 changes: 4 additions & 5 deletions spec/lib/pre_assembly/digital_object_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@ def add_object_files(extension = 'tif')
(1..2).each do |i|
f = "image#{i}.#{extension}"
dobj.object_files.push PreAssembly::ObjectFile.new(
path: "#{dobj.bundle_dir}/#{dru}/#{f}",
"#{dobj.bundle_dir}/#{dru}/#{f}",
relative_path: f,
exclude_from_content: false,
checksum: i.to_s * 4
)
end
Expand Down Expand Up @@ -123,7 +122,7 @@ def add_object_files(extension = 'tif')
n = files.size
m = n / 2
dobj.object_files = files.map do |f|
PreAssembly::ObjectFile.new(exclude_from_content: false, relative_path: f)
PreAssembly::ObjectFile.new("/path/to/#{f}", relative_path: f)
end
# All of them are included in content.
expect(dobj.content_object_files.size).to eq(n)
Expand Down Expand Up @@ -247,7 +246,7 @@ def add_object_files(extension = 'tif')
n = files.size
m = n / 2
dobj.object_files = files.map do |f|
PreAssembly::ObjectFile.new(exclude_from_content: false, relative_path: f)
PreAssembly::ObjectFile.new("/path/to/#{f}", relative_path: f)
end
# All of them are included in content.
expect(dobj.content_object_files.size).to eq(n)
Expand Down Expand Up @@ -310,7 +309,7 @@ def add_object_files(extension = 'tif')
# Generate some object_files.
files = %w[file5.tif file4.tif file3.tif file2.tif file1.tif file0.tif]
dobj.object_files = files.map do |f|
PreAssembly::ObjectFile.new(exclude_from_content: false, relative_path: f)
PreAssembly::ObjectFile.new("/path/to/#{f}", relative_path: f)
end
# All of them are included in content.
expect(dobj.content_object_files.size).to eq(files.size)
Expand Down
2 changes: 1 addition & 1 deletion spec/lib/pre_assembly/object_file_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
RSpec.describe PreAssembly::ObjectFile do
let(:object_file) { described_class.new(path: 'spec/test_data/flat_dir_images/image1.tif') }
let(:object_file) { described_class.new('spec/test_data/flat_dir_images/image1.tif') }

describe 'initialization' do
it 'can initialize an ObjectFile' do
Expand Down

0 comments on commit 8a1911b

Please sign in to comment.