Skip to content

Commit

Permalink
Removing Slug generation functionality from the EphemeraProjectDecorator
Browse files Browse the repository at this point in the history
  • Loading branch information
jrgriffiniii committed Oct 17, 2017
1 parent c30510a commit 4b9ab1c
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 44 deletions.
42 changes: 1 addition & 41 deletions app/decorators/ephemera_project_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,56 +30,16 @@ def title
super.first
end

# Access (or generate) the slug ID for the decorated resource
# @return [String] the slug value
def slug
value = super
generated_slug.value unless value.present?
Array.wrap(super).first
end

def iiif_manifest_attributes
local_attributes(self.class.iiif_manifest_attributes).merge iiif_manifest_exhibit
end

# A local identifier (slug) generated for EphemeraProjects
class Slug
attr_reader :value

# Initialize using a prefix, seed, and optional delimiter
# @param prefix [String] the prefix for the slug ID
# @param seed [String] the value used to generate the suffix for the slug
# @param delimiter [String] the delimiter used between the prefix and suffix
def initialize(prefix:, seed:, delimiter: '-')
@prefix = prefix
@seed = seed
@delimiter = delimiter
@value = generate
end
alias to_s value

private

# Generate the slug ID value
# @return [String] the string value used as the slug
def generate
@prefix + @delimiter + @seed.slice(0, 4)
end
end

private

# Generate the slug prefix from the existing label
# @return [String] the prefix for the slug
def generated_slug_prefix
title.gsub(/\s/, '_').downcase
end

# Generate the slug value from the Valkyrie Resource ID
# @return [Slug] the slug for the resource
def generated_slug
@slug ||= Slug.new(prefix: generated_slug_prefix, seed: model.id.to_s)
end

# Generate the Hash for the IIIF Manifest metadata exposing the slug as an "Exhibit" property
# @return [Hash] the exhibit metadata hash
def iiif_manifest_exhibit
Expand Down
3 changes: 2 additions & 1 deletion spec/controllers/ephemera_projects_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
let(:user) { FactoryGirl.create(:admin) }
let(:valid_params) do
{
title: ['Project 1']
title: ['Project 1'],
slug: ['test-project-1234']
}
end
let(:invalid_params) do
Expand Down
4 changes: 2 additions & 2 deletions spec/decorators/ephemera_project_decorator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
end
describe '#slug' do
it 'generates a slug' do
expect(decorator.slug).to eq "test_project-#{resource.id.to_s.slice(0, 4)}"
expect(decorator.slug).to eq "test_project-1234"
end
end
describe '#iiif_manifest_attributes' do
it 'includes the "exhibit" property in the IIIF Manifest metadata' do
expect(decorator.iiif_manifest_attributes).to include(exhibit: "test_project-#{resource.id.to_s.slice(0, 4)}")
expect(decorator.iiif_manifest_attributes).to include(exhibit: "test_project-1234")
end
end
end
1 change: 1 addition & 0 deletions spec/factories/ephemera_project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
FactoryGirl.define do
factory :ephemera_project do
title 'Test Project'
slug 'test_project-1234'
to_create do |instance|
Valkyrie.config.metadata_adapter.persister.save(resource: instance)
end
Expand Down

0 comments on commit 4b9ab1c

Please sign in to comment.