Skip to content

Commit

Permalink
namespace change for autoloading
Browse files Browse the repository at this point in the history
  • Loading branch information
stkenny committed Nov 6, 2024
1 parent 3e60ff3 commit a57bcf3
Show file tree
Hide file tree
Showing 31 changed files with 98 additions and 98 deletions.
2 changes: 1 addition & 1 deletion app/controllers/dri_batch_ingest/application_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true
class DriBatchIngest::ApplicationController < ActionController::Base
class DRIBatchIngest::ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery
Expand Down
16 changes: 8 additions & 8 deletions app/controllers/dri_batch_ingest/ingest_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
require 'dri_batch_ingest/processors/entry_processor'
require 'dri_batch_ingest/csv_creator'

class DriBatchIngest::IngestController < ApplicationController
class DRIBatchIngest::IngestController < ApplicationController
before_action :authenticate_user!
before_action :read_only, except: [:index, :show]

Expand All @@ -17,7 +17,7 @@ def index; end

def new
@collections = user_collections
@ingests = DriBatchIngest::UserIngest.where(user_id: current_user.id).order(created_at: :desc).page(params[:page]).per(5)
@ingests = DRIBatchIngest::UserIngest.where(user_id: current_user.id).order(created_at: :desc).page(params[:page]).per(5)
@batches = user_batches

begin
Expand All @@ -28,7 +28,7 @@ def new
end

def show
@batch = DriBatchIngest::IngestBatch.find(params[:id])
@batch = DRIBatchIngest::IngestBatch.find(params[:id])

@media_objects = if params[:status]
@batch.media_objects.status(params[:status]).page(params[:page]).per(25)
Expand All @@ -39,26 +39,26 @@ def show

def create
collection = params[:collection_id]
ingest = DriBatchIngest::UserIngest.create(user_id: current_user.id)
ingest = DRIBatchIngest::UserIngest.create(user_id: current_user.id)

if params.dig(:type) == 'manifest'
Resque.enqueue(DriBatchIngest::ProcessManifest, ingest.id, collection, params['selected_files'], provider_tokens)
Resque.enqueue(DRIBatchIngest::ProcessManifest, ingest.id, collection, params['selected_files'], provider_tokens)
else
metadata_path = params[:metadata_path]
asset_path = params[:asset_path]
preservation_path = params[:preservation_path]

Resque.enqueue(DriBatchIngest::CreateManifest, ingest.id, base_dir, current_user.email, collection, metadata_path, asset_path, preservation_path)
Resque.enqueue(DRIBatchIngest::CreateManifest, ingest.id, base_dir, current_user.email, collection, metadata_path, asset_path, preservation_path)
end

redirect_to ingests_url(ingest)
end

def update
@batch = DriBatchIngest::IngestBatch.find(params[:id])
@batch = DRIBatchIngest::IngestBatch.find(params[:id])

media_object_ids = @batch.media_objects.status('FAILED').pluck(:id)
Resque.enqueue(DriBatchIngest::ProcessBatch, @batch.id, media_object_ids)
Resque.enqueue(DRIBatchIngest::ProcessBatch, @batch.id, media_object_ids)

redirect_to ingests_url
end
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/dri_batch_ingest/master_files_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true
class DriBatchIngest::MasterFilesController < ApplicationController
class DRIBatchIngest::MasterFilesController < ApplicationController
before_action :authenticate_user_from_token!
before_action :authenticate_user!

Expand All @@ -10,7 +10,7 @@ def update
params[:master_file][:file_location] = location
end

master_file = DriBatchIngest::MasterFile.find(params[:file_id])
master_file = DRIBatchIngest::MasterFile.find(params[:file_id])
master_file.update_attributes(update_params)
master_file.save

Expand Down
6 changes: 3 additions & 3 deletions app/controllers/dri_batch_ingest/media_objects_controller.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# frozen_string_literal: true
require 'filesize'

class DriBatchIngest::MediaObjectsController < ApplicationController
class DRIBatchIngest::MediaObjectsController < ApplicationController
before_action :authenticate_user_from_token!
before_action :authenticate_user!

def show
@batch = DriBatchIngest::IngestBatch.find(params[:id])
@media_object = DriBatchIngest::MediaObject.find(params[:media_id])
@batch = DRIBatchIngest::IngestBatch.find(params[:id])
@media_object = DRIBatchIngest::MediaObject.find(params[:media_id])

@files = @media_object.parts.page params[:page]

Expand Down
4 changes: 2 additions & 2 deletions app/controllers/dri_batch_ingest/user_ingests_controller.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# frozen_string_literal: true
class DriBatchIngest::UserIngestsController < ApplicationController
class DRIBatchIngest::UserIngestsController < ApplicationController
before_action :authenticate_user!

def index
@ingests = DriBatchIngest::UserIngest.where(user_id: current_user.id).order(created_at: :desc).page(params[:page]).per(10)
@ingests = DRIBatchIngest::UserIngest.where(user_id: current_user.id).order(created_at: :desc).page(params[:page]).per(10)
@batches = user_batches
end

Expand Down
2 changes: 1 addition & 1 deletion app/helpers/dri_batch_ingest/application_helper.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true
module DriBatchIngest
module DRIBatchIngest
module ApplicationHelper
end
end
6 changes: 3 additions & 3 deletions app/models/dri_batch_ingest/ingest_batch.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# frozen_string_literal: true
module DriBatchIngest
module DRIBatchIngest
class IngestBatch < ActiveRecord::Base
belongs_to :user_ingest, class_name: 'DriBatchIngest::UserIngest'
has_many :media_objects, class_name: 'DriBatchIngest::MediaObject'
belongs_to :user_ingest, class_name: 'DRIBatchIngest::UserIngest'
has_many :media_objects, class_name: 'DRIBatchIngest::MediaObject'

def finished?
media_objects.all?(&:finished_processing?)
Expand Down
4 changes: 2 additions & 2 deletions app/models/dri_batch_ingest/master_file.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true
module DriBatchIngest
module DRIBatchIngest
class MasterFile < ActiveRecord::Base
belongs_to :media_object, class_name: 'DriBatchIngest::MediaObject'
belongs_to :media_object, class_name: 'DRIBatchIngest::MediaObject'

END_STATES = %w[CANCELLED COMPLETED FAILED].freeze

Expand Down
12 changes: 6 additions & 6 deletions app/models/dri_batch_ingest/media_object.rb
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
# frozen_string_literal: true
module DriBatchIngest
module DRIBatchIngest
class MediaObject < ActiveRecord::Base
belongs_to :ingest_batch, class_name: 'DriBatchIngest::IngestBatch'
has_many :parts, class_name: 'DriBatchIngest::MasterFile'
belongs_to :ingest_batch, class_name: 'DRIBatchIngest::IngestBatch'
has_many :parts, class_name: 'DRIBatchIngest::MasterFile'

scope :status, lambda { |status|
joins(:parts).where('dri_batch_ingest_master_files.status_code' => status).distinct
}

scope :pending, -> { joins(:parts).where('dri_batch_ingest_master_files.status_code' => 'PENDING').distinct }

scope :excluding_failed, -> { where(['dri_batch_ingest_media_objects.id NOT IN (?)', DriBatchIngest::MediaObject.status('FAILED').pluck(:id)]) if failed.any? }
scope :excluding_failed, -> { where(['dri_batch_ingest_media_objects.id NOT IN (?)', DRIBatchIngest::MediaObject.status('FAILED').pluck(:id)]) if failed.any? }

scope :failed, -> { DriBatchIngest::MediaObject.status('FAILED') }
scope :failed, -> { DRIBatchIngest::MediaObject.status('FAILED') }

scope :completed, -> { DriBatchIngest::MediaObject.status('COMPLETED') }
scope :completed, -> { DRIBatchIngest::MediaObject.status('COMPLETED') }

def destroy
parts.each(&:destroy)
Expand Down
4 changes: 2 additions & 2 deletions app/models/dri_batch_ingest/user_ingest.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true
class DriBatchIngest::UserIngest < ActiveRecord::Base
class DRIBatchIngest::UserIngest < ActiveRecord::Base
belongs_to :user, class_name: 'UserGroup::User'

has_many :batches, class_name: 'DriBatchIngest::IngestBatch'
has_many :batches, class_name: 'DRIBatchIngest::IngestBatch'
end
12 changes: 6 additions & 6 deletions app/workers/dri_batch_ingest/create_manifest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
require 'avalon/batch'
require 'dri_batch_ingest/processors'

class DriBatchIngest::CreateManifest
class DRIBatchIngest::CreateManifest
@queue = :create_manifest

def self.perform(ingest_id, base_dir, email, collection, metadata_path, asset_path, preservation_path)
creator = DriBatchIngest::CsvCreator.new(
creator = DRIBatchIngest::CsvCreator.new(
base_dir,
email,
collection
Expand All @@ -17,11 +17,11 @@ def self.perform(ingest_id, base_dir, email, collection, metadata_path, asset_pa
package = Avalon::Batch::Package.new(
creator.csv_file,
collection,
DriBatchIngest::Processors::EntryProcessor
DRIBatchIngest::Processors::EntryProcessor
)

ingest = DriBatchIngest::UserIngest.find(ingest_id)
batch = DriBatchIngest::IngestBatch.create(
ingest = DRIBatchIngest::UserIngest.find(ingest_id)
batch = DRIBatchIngest::IngestBatch.create(
collection_id: collection,
email: package.manifest.email,
user_ingest_id: ingest.id
Expand All @@ -35,7 +35,7 @@ def self.perform(ingest_id, base_dir, email, collection, metadata_path, asset_pa

ingest.batches << batch

Resque.enqueue(DriBatchIngest::ProcessBatch, batch.id)
Resque.enqueue(DRIBatchIngest::ProcessBatch, batch.id)
ingest.save
end
end
6 changes: 3 additions & 3 deletions app/workers/dri_batch_ingest/process_batch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@
require 'avalon/batch'
require 'rest-client'

class DriBatchIngest::ProcessBatch
class DRIBatchIngest::ProcessBatch
@queue = :process_batch

def self.perform(batch_id, media_object_ids = nil)
batch = DriBatchIngest::IngestBatch.find(batch_id)
batch = DRIBatchIngest::IngestBatch.find(batch_id)
user = UserGroup::User.find(batch.user_ingest.user_id)
collection_id = batch.collection_id

media_objects = media_object_ids || batch.media_objects

media_objects.each do |mo|
media_object = mo.is_a?(DriBatchIngest::MediaObject) ? mo : DriBatchIngest::MediaObject.find(mo)
media_object = mo.is_a?(DRIBatchIngest::MediaObject) ? mo : DRIBatchIngest::MediaObject.find(mo)
ingest_message = process_media_object(media_object, collection_id)

Resque.enqueue(::ProcessBatchIngest, user.id, collection_id, ingest_message.to_json)
Expand Down
10 changes: 5 additions & 5 deletions app/workers/dri_batch_ingest/process_manifest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
require 'avalon/batch'
require 'dri_batch_ingest/processors'

class DriBatchIngest::ProcessManifest
class DRIBatchIngest::ProcessManifest
@queue = :process_manifest

def self.perform(ingest_id, collection, selected_files, provider_tokens)
retriever = BrowseEverything::Retriever.new
ingest = DriBatchIngest::UserIngest.find(ingest_id)
ingest = DRIBatchIngest::UserIngest.find(ingest_id)

FileUtils.mkdir_p(File.join(Settings.downloads.directory, collection))

Expand All @@ -18,10 +18,10 @@ def self.perform(ingest_id, collection, selected_files, provider_tokens)
package = Avalon::Batch::Package.new(
manifest,
collection,
DriBatchIngest::Processors::EntryProcessor
DRIBatchIngest::Processors::EntryProcessor
)

batch = DriBatchIngest::IngestBatch.create(collection_id: collection, email: package.manifest.email, user_ingest_id: ingest.id)
batch = DRIBatchIngest::IngestBatch.create(collection_id: collection, email: package.manifest.email, user_ingest_id: ingest.id)

package.process!(
'batch' => batch.id,
Expand All @@ -31,7 +31,7 @@ def self.perform(ingest_id, collection, selected_files, provider_tokens)

ingest.batches << batch

Resque.enqueue(DriBatchIngest::ProcessBatch, batch.id)
Resque.enqueue(DRIBatchIngest::ProcessBatch, batch.id)
end

ingest.save
Expand Down
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
DriBatchIngest::Engine.routes.draw do
DRIBatchIngest::Engine.routes.draw do

get '/', to: "ingest#new"

Expand Down
2 changes: 1 addition & 1 deletion dri_batch_ingest.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require "dri_batch_ingest/version"
# Describe your gem and declare its dependencies:
Gem::Specification.new do |s|
s.name = "dri_batch_ingest"
s.version = DriBatchIngest::VERSION
s.version = DRIBatchIngest::VERSION
s.authors = ["Stuart Kenny"]
s.email = ["[email protected]"]
s.homepage = "https://github.com/Digital-Repository-of-Ireland/dri_batch_ingest"
Expand Down
2 changes: 1 addition & 1 deletion lib/dri_batch_ingest.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true
module DriBatchIngest
module DRIBatchIngest
require 'dri_batch_ingest/engine'
require 'dri_batch_ingest/version'
end
2 changes: 1 addition & 1 deletion lib/dri_batch_ingest/csv_creator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
require "csv"
require "tmpdir"

class DriBatchIngest::CsvCreator
class DRIBatchIngest::CsvCreator
attr_reader :csv_file

def initialize(base_dir, user_email, collection)
Expand Down
4 changes: 2 additions & 2 deletions lib/dri_batch_ingest/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
require 'jstree-rails-4'
require 'browse_everything'

module DriBatchIngest
module DRIBatchIngest
class Engine < ::Rails::Engine
isolate_namespace DriBatchIngest
isolate_namespace DRIBatchIngest

config.generators do |g|
g.test_framework :rspec
Expand Down
2 changes: 1 addition & 1 deletion lib/dri_batch_ingest/processors.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true
module DriBatchIngest
module DRIBatchIngest
module Processors
autoload :EntryProcessor, 'dri_batch_ingest/processors/entry_processor'
end
Expand Down
8 changes: 4 additions & 4 deletions lib/dri_batch_ingest/processors/entry_processor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
require 'avalon/batch'
require 'json'

module DriBatchIngest
module DRIBatchIngest
module Processors
class EntryProcessor < Avalon::Batch::Entry
def media_object
@media_object ||= DriBatchIngest::MediaObject.new(collection: @manifest.package.collection)
@media_object ||= DRIBatchIngest::MediaObject.new(collection: @manifest.package.collection)
end

def process!(opts = {})
batch = DriBatchIngest::IngestBatch.find(opts['batch'])
batch = DRIBatchIngest::IngestBatch.find(opts['batch'])
user = UserGroup::User.find(batch.user_ingest.user_id)

media_object.ingest_batch = batch
Expand All @@ -31,7 +31,7 @@ def process!(opts = {})
private

def create_master_file(file_spec)
master_file = DriBatchIngest::MasterFile.new
master_file = DRIBatchIngest::MasterFile.new
master_file.media_object = media_object
master_file.metadata = true if file_spec.key?(:label) && file_spec[:label] == 'metadata'
master_file.preservation = true if file_spec.key?(:label) && file_spec[:label] == 'preservation'
Expand Down
2 changes: 1 addition & 1 deletion lib/dri_batch_ingest/version.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# frozen_string_literal: true
module DriBatchIngest
module DRIBatchIngest
VERSION = "1.3.2"
end
2 changes: 1 addition & 1 deletion spec/factories/models.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
FactoryBot.define do
factory :user_ingest, class: DriBatchIngest::UserIngest do |u|
factory :user_ingest, class: DRIBatchIngest::UserIngest do |u|

end
end
2 changes: 1 addition & 1 deletion spec/lib/dri_batch_ingest/csv_creator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
require 'csv'
require 'dri_batch_ingest/csv_creator'

describe DriBatchIngest::CsvCreator do
describe DRIBatchIngest::CsvCreator do

it 'should create a csv from files' do
base_dir = File.join(file_fixture_path, 'ingest')
Expand Down
Loading

0 comments on commit a57bcf3

Please sign in to comment.