Skip to content

Commit

Permalink
Deprecate Hyrax's Noid functionality
Browse files Browse the repository at this point in the history
Enable using ActiveFedora::Noid::Model if desired
  • Loading branch information
jcoyne committed May 26, 2017
1 parent a4cff81 commit 48951ef
Show file tree
Hide file tree
Showing 13 changed files with 40 additions and 27 deletions.
2 changes: 1 addition & 1 deletion app/models/concerns/hyrax/admin_set_behavior.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module AdminSetBehavior
extend ActiveSupport::Concern

include Hydra::AccessControls::WithAccessRight
include Hyrax::Noid
include ActiveFedora::Noid::Model if Hyrax.config.enable_noids?
include Hyrax::HumanReadableType
include Hyrax::HasRepresentative

Expand Down
2 changes: 1 addition & 1 deletion app/models/concerns/hyrax/collection_behavior.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module CollectionBehavior
include Hydra::AccessControls::Permissions
include Hyrax::CoreMetadata
include Hydra::Works::CollectionBehavior
include Hyrax::Noid
include ActiveFedora::Noid::Model if Hyrax.config.enable_noids?
include Hyrax::HumanReadableType
include Hyrax::HasRepresentative
include Hyrax::Permissions
Expand Down
2 changes: 1 addition & 1 deletion app/models/concerns/hyrax/file_set_behavior.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module FileSetBehavior
include Hyrax::FileSet::Characterization
include Hydra::WithDepositor
include Serializers
include Hyrax::Noid
include ActiveFedora::Noid::Model if Hyrax.config.enable_noids?
include Hyrax::FileSet::Derivatives
include Permissions
include Hyrax::FileSet::Indexing
Expand Down
2 changes: 1 addition & 1 deletion app/models/concerns/hyrax/work_behavior.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module WorkBehavior
extend ActiveSupport::Concern
include Hydra::Works::WorkBehavior
include HumanReadableType
include Noid
include ActiveFedora::Noid::Model if Hyrax.config.enable_noids?
include Permissions
include Serializers
include Hydra::WithDepositor
Expand Down
5 changes: 5 additions & 0 deletions app/services/hyrax/noid.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ module Hyrax
module Noid
extend ActiveSupport::Concern

included do
Deprecation.warn(self, "Hyrax::Noid is deprecated and will be removed in Hyrax 3.0. " \
"Instead add 'include ActiveFedora::Noid::Model' to the classes that you want to use noids on.")
end

## This overrides the default behavior, which is to ask Fedora for an id
# @see ActiveFedora::Persistence.assign_id
def assign_id
Expand Down
2 changes: 1 addition & 1 deletion hyrax.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ EOF
spec.add_dependency 'rdf-rdfxml' # controlled vocabulary importer
spec.add_dependency 'clipboard-rails', '~> 1.5'
spec.add_dependency 'rails_autolink', '~> 1.1'
spec.add_dependency 'active_fedora-noid', '~> 2.0', '>= 2.0.2'
spec.add_dependency 'active_fedora-noid', '~> 2.2' # Deprecated. Remove in Hyrax 3.0
spec.add_dependency 'awesome_nested_set', '~> 3.1'
spec.add_dependency 'breadcrumbs_on_rails', '~> 3.0'
spec.add_dependency 'kaminari_route_prefix', '~> 0.1.1'
Expand Down
5 changes: 0 additions & 5 deletions lib/generators/hyrax/install_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ class Install < Rails::Generators::Base
14. Updates simple_form to use browser validations
15. Installs Blacklight gallery (and removes it's scss)
16. Install jquery-datatables
17. Initializes the active-fedora_noid database-backed minter
"""

def run_required_generators
Expand Down Expand Up @@ -160,9 +159,5 @@ def datatables
" *= require dataTables/bootstrap/3/jquery.dataTables.bootstrap\n"
end
end

def af_noid_database_minter_initialize
generate 'active_fedora:noid:install'
end
end
end
13 changes: 0 additions & 13 deletions lib/generators/hyrax/templates/config/hyrax.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,6 @@
# If you have ffmpeg installed and want to transcode audio and video set to true
# config.enable_ffmpeg = false

# Hyrax uses NOIDs for files and collections instead of Fedora UUIDs
# where NOID = 10-character string and UUID = 32-character string w/ hyphens
# config.enable_noids = true

# Template for your repository's NOID IDs
# config.noid_template = ".reeddeeddk"

# Use the database-backed minter class
# config.noid_minter_class = ActiveFedora::Noid::Minter::Db

# Store identifier minter's state in a file for later replayability
# config.minter_statefile = '/tmp/minter-state'

# Prefix for Redis keys
# config.redis_namespace = "hyrax"

Expand Down
10 changes: 9 additions & 1 deletion lib/hyrax/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,22 +103,30 @@ def max_days_between_fixity_checks
deprecation_deprecate :max_days_between_audits= => "use max_days_between_fixity_checks= instead"

attr_writer :enable_noids
deprecation_deprecate :enable_noids= => "Hyrax's noid integration will be removed in 3.0. Instead " \
"add 'include ActiveFedora::Noid::Model' to those models that you want to use NOIDs"
def enable_noids?
return @enable_noids unless @enable_noids.nil?
@enable_noids = true
@enable_noids = false
end

attr_writer :noid_template
deprecation_deprecate :noid_template= => "Hyrax's noid integration will be removed in 3.0. Instead " \
"set 'ActiveFedora::Noid.config.template=' directly"
def noid_template
@noid_template ||= '.reeddeeddk'
end

attr_writer :noid_minter_class
deprecation_deprecate :noid_minter_class= => "Hyrax's noid integration will be removed in 3.0. Instead " \
"set 'ActiveFedora::Noid.config.minter_class=' directly"
def noid_minter_class
@noid_minter_class ||= ActiveFedora::Noid::Minter::Db
end

attr_writer :minter_statefile
deprecation_deprecate :minter_statefile= => "Hyrax's noid integration will be removed in 3.0. Instead " \
"set 'ActiveFedora::Noid.config.statefile=' directly"
def minter_statefile
@minter_statefile ||= '/tmp/minter-state'
end
Expand Down
8 changes: 5 additions & 3 deletions lib/hyrax/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,11 @@ class Engine < ::Rails::Engine
ActiveFedora::Base.translate_uri_to_id = c.translate_uri_to_id
ActiveFedora::Base.translate_id_to_uri = c.translate_id_to_uri

ActiveFedora::Noid.config.template = c.noid_template
ActiveFedora::Noid.config.minter_class = c.noid_minter_class
ActiveFedora::Noid.config.statefile = c.minter_statefile
if c.enable_noids?
ActiveFedora::Noid.config.template = c.noid_template
ActiveFedora::Noid.config.minter_class = c.noid_minter_class
ActiveFedora::Noid.config.statefile = c.minter_statefile
end
end
end

Expand Down
1 change: 1 addition & 0 deletions spec/models/file_set_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ class AltFile < ActiveFedora::Base
describe 'noid integration', :clean_repo do
let(:service) { instance_double(ActiveFedora::Noid::Service, mint: noid) }
before do
Hyrax.config.enable_noids = true
allow(ActiveFedora::Noid::Service).to receive(:new).and_return(service)
end

Expand Down
5 changes: 5 additions & 0 deletions spec/services/hyrax/noid_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ def initialize(id:)
end
end
end

before do
allow(Deprecation).to receive(:warn)
end

let(:object) { class_with_noids.new(id: 1234) }

describe 'when noids are not enabled' do
Expand Down
10 changes: 10 additions & 0 deletions spec/test_app_templates/lib/generators/test_app_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,14 @@ def enable_arkivo_api
def relax_routing_constraint
gsub_file 'config/initializers/arkivo_constraint.rb', 'false', 'true'
end

# We've turned off noid by default, but show we can turn it on if we want to.
def enable_noids
generate 'active_fedora:noid:install'
config = 'config/initializers/hyrax.rb'
anchor = "Hyrax.config do |config|\n"
inject_into_file config, after: anchor do
" config.enable_noids = true\n"
end
end
end

0 comments on commit 48951ef

Please sign in to comment.