Skip to content

Commit

Permalink
Merge pull request #1776 from sul-dlss/delegate-index
Browse files Browse the repository at this point in the history
Use a delegator for the hierarchical file
  • Loading branch information
jcoyne authored Nov 17, 2023
2 parents 79e433e + 27f5408 commit 28ef5a3
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion app/models/embed/hierarchical_contents.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def contents
attr_reader :resources

def file_contents
resources.map(&:files).flatten
resources.map(&:files).flatten.map { |file| HierarchicalFile.new(file) }
end

def add_to_hierarchy(file, root_directory)
Expand Down
7 changes: 7 additions & 0 deletions app/models/embed/hierarchical_file.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

module Embed
class HierarchicalFile < SimpleDelegator
attr_accessor :index
end
end
3 changes: 0 additions & 3 deletions app/models/embed/purl/resource_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,8 @@ def initialize(druid, description, file, rights)
@description = description
@file = file
@rights = rights
@index = nil
end

attr_accessor :index

def label
@description
end
Expand Down
2 changes: 1 addition & 1 deletion spec/models/embed/hierarchical_contents_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
expect(root_dir.title).to eq ''
expect(root_dir.files.count).to eq 1
file1 = root_dir.files.first
expect(file1).to be_an Embed::Purl::ResourceFile
expect(file1).to be_an Embed::HierarchicalFile
expect(file1.title).to eq 'Title_of_the_PDF.pdf'
expect(file1.index).to eq 1
expect(root_dir.dirs.count).to eq 1
Expand Down

0 comments on commit 28ef5a3

Please sign in to comment.