Skip to content

Commit

Permalink
moku deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
gkostin1966 committed Jun 11, 2021
1 parent 831c5bc commit 8f16fc9
Show file tree
Hide file tree
Showing 16 changed files with 61 additions and 67 deletions.
3 changes: 3 additions & 0 deletions .rubocop.yml
Expand Up @@ -30,6 +30,9 @@ RSpec/ExampleLength:
RSpec/MultipleExpectations:
Enabled: false

RSpec/MultipleMemoizedHelpers:
Enabled: false

RSpec/NestedGroups:
Max: 4

Expand Down
1 change: 0 additions & 1 deletion Gemfile
Expand Up @@ -87,7 +87,6 @@ gem 'jquery-rails', '~> 4.3'
# Moku freeze
gem 'nio4r', '= 2.5.1'
gem 'puma', '4.3.8'
gem 'rake'

group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
Expand Down
14 changes: 6 additions & 8 deletions Gemfile.lock
Expand Up @@ -101,7 +101,7 @@ GEM
factory_bot (~> 5.2.0)
railties (>= 4.2.0)
ffi (1.15.1)
fugit (1.4.5)
fugit (1.5.0)
et-orbi (~> 1.1, >= 1.1.8)
raabro (~> 1.4)
globalid (0.4.2)
Expand Down Expand Up @@ -146,13 +146,13 @@ GEM
marcel (1.0.1)
method_source (1.0.0)
mini_mime (1.1.0)
mini_portile2 (2.5.3)
minitest (5.14.4)
msgpack (1.4.2)
mysql2 (0.4.10)
nio4r (2.5.1)
nokogiri (1.11.7-x86_64-darwin)
racc (~> 1.4)
nokogiri (1.11.7-x86_64-linux)
nokogiri (1.11.7)
mini_portile2 (~> 2.5.0)
racc (~> 1.4)
parallel (1.20.1)
parser (3.0.1.1)
Expand Down Expand Up @@ -311,8 +311,7 @@ GEM
yard (0.9.26)

PLATFORMS
x86_64-darwin-18
x86_64-linux
ruby

DEPENDENCIES
bootsnap (~> 1.4.6)
Expand All @@ -333,7 +332,6 @@ DEPENDENCIES
nio4r (= 2.5.1)
puma (= 4.3.8)
rails (~> 5.2.6)
rake
rspec-rails (~> 4.0)
rubocop-performance (~> 1.2)
rubocop-rspec (~> 1.32)
Expand All @@ -350,4 +348,4 @@ DEPENDENCIES
yard (~> 0.9.20)

BUNDLED WITH
2.2.4
2.1.4
2 changes: 1 addition & 1 deletion app/controllers/identifiers_controller.rb
Expand Up @@ -53,7 +53,7 @@ def create # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
end
end

def update # rubocop:disable Metrics/PerceivedComplexity, Metrics/MethodLength, Metrics/AbcSize
def update # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
update_identifier_params = identifier_params
update_identifier_params[:uuid] = if update_identifier_params[:uuid].present?
Identifier.find(update_identifier_params[:uuid]).uuid
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/programs_controller.rb
Expand Up @@ -7,7 +7,7 @@ def index

def show; end

def run # rubocop:disable Metrics/MethodLength, Metrics/CyclomaticComplexity, Metrics/AbcSize, Metrics/PerceivedComplexity
def run # rubocop:disable Metrics/MethodLength, Metrics/CyclomaticComplexity, Metrics/AbcSize
case params[:id]
when 'assemble_marc_files'
options = {}
Expand Down
2 changes: 1 addition & 1 deletion app/models/identifier.rb
Expand Up @@ -31,7 +31,7 @@ def resource_id
end

def resource_token
@resource_token ||= resource_type.to_s + ':' + resource_id.to_s
@resource_token ||= "#{resource_type}:#{resource_id}"
end

protected
Expand Down
8 changes: 1 addition & 7 deletions app/models/resource.rb
Expand Up @@ -26,7 +26,7 @@ def resource_id
end

def resource_token
@resource_token ||= resource_type.to_s + ':' + resource_id.to_s
@resource_token ||= "#{resource_type}:#{resource_id}"
end

protected
Expand All @@ -44,10 +44,4 @@ def initialize(uuid)

class NullResource < Resource
private_class_method :new

private

def initialize(uuid)
super(uuid)
end
end
10 changes: 5 additions & 5 deletions app/models/uuid.rb
Expand Up @@ -44,28 +44,28 @@ def uuid_generator_unpacked
uuid_unpack(uuid_generator_packed)
end

def uuid_pack(unpacked) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
def uuid_pack(unpacked) # rubocop:disable Metrics/MethodLength
text = unpacked.dup
text.delete!('-')
return uuid_null_packed unless text.length == 32

bytes = []
16.times do |i|
n = 2 * i
bytes.push(('0x' + text[n] + text[n + 1]).to_i(16))
bytes.push(("0x#{text[n]}#{text[n + 1]}").to_i(16))
end
bytes.pack('C*').force_encoding('ascii-8bit')
rescue StandardError => _e
uuid_null_packed
end

def uuid_unpack(packed) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
def uuid_unpack(packed) # rubocop:disable Metrics/MethodLength
return uuid_null_unpacked unless packed.length == 16

unpacked = []
16.times do |i|
byte = packed[i].bytes[0].to_s(16)
unpacked.push(byte.length == 1 ? '0' + byte : byte)
unpacked.push(byte.length == 1 ? "0#{byte}" : byte)
end
unpacked = unpacked.join
unpacked.insert(8, '-')
Expand Down Expand Up @@ -105,7 +105,7 @@ def resource_id
end

def resource_token
@resource_token ||= resource_type.to_s + ':' + resource_id.to_s
@resource_token ||= "#{resource_type}:#{resource_id}"
end

protected
Expand Down
2 changes: 1 addition & 1 deletion app/modules/lib_ptg_box/catalog.rb
Expand Up @@ -20,7 +20,7 @@ def marc(doi)
nil
end

def marcs # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
def marcs # rubocop:disable Metrics/MethodLength
@marcs ||= begin
marcs = []
MarcRecord.where(folder: @collection.key).each do |marc_record|
Expand Down
2 changes: 1 addition & 1 deletion app/modules/lib_ptg_box/lib_ptg_box.rb
Expand Up @@ -93,7 +93,7 @@ def synchronize_marc_records(collection) # rubocop:disable Metrics/MethodLength,
log
end

def synchronize_kbart_files(collection) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize, Metrics/CyclomaticComplexity
def synchronize_kbart_files(collection) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
log = []

# Previous KBART records list
Expand Down
16 changes: 8 additions & 8 deletions app/programs/assemble_marc_files/assemble_marc_files.rb
Expand Up @@ -76,8 +76,8 @@ def recreate_selection_marc_files(record, selection) # rubocop:disable Metrics/M
# The "solution", I guess, is to write the XML file out first,
# but I'd document the @^%& out of it.

xml_writer = MARC::XMLWriter.new(filename + '.xml')
writer = MARC::Writer.new(filename + '.mrc')
xml_writer = MARC::XMLWriter.new("#{filename}.xml")
writer = MARC::Writer.new("#{filename}.mrc")
selection_works.keys.sort.each do |key|
work = selection_works[key]
xml_writer.write(work.marc.entry)
Expand All @@ -93,7 +93,7 @@ def create_selection_marc_delta_files(selection) # rubocop:disable Metrics/Metho
this_delta = Time.now
this_delta_date = Date.new(this_delta.year, this_delta.month, 15)

filename = selection.name + '_update_' + format("%04d-%02d-%02d", this_delta_date.year, this_delta_date.month, this_delta_date.day)
filename = "#{selection.name}_update_#{format('%04d-%02d-%02d', this_delta_date.year, this_delta_date.month, this_delta_date.day)}"

selection_works = {}
selection.works.each do |work|
Expand All @@ -116,8 +116,8 @@ def create_selection_marc_delta_files(selection) # rubocop:disable Metrics/Metho
# The "solution", I guess, is to write the XML file out first,
# but I'd document the @^%& out of it.

xml_writer = MARC::XMLWriter.new(filename + '.xml')
writer = MARC::Writer.new(filename + '.mrc')
xml_writer = MARC::XMLWriter.new("#{filename}.xml")
writer = MARC::Writer.new("#{filename}.mrc")
selection_works.keys.sort.each do |key|
work = selection_works[key]
xml_writer.write(work.marc.entry)
Expand All @@ -128,7 +128,7 @@ def create_selection_marc_delta_files(selection) # rubocop:disable Metrics/Metho
end

def recreate_collection_marc_files(collection) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
filename = collection.name + '_Complete'
filename = "#{collection.name}_Complete"

collection_works = {}
collection.selections.each do |selection|
Expand All @@ -152,8 +152,8 @@ def recreate_collection_marc_files(collection) # rubocop:disable Metrics/MethodL
# The "solution", I guess, is to write the XML file out first,
# but I'd document the @^%& out of it.

xml_writer = MARC::XMLWriter.new(filename + '.xml')
writer = MARC::Writer.new(filename + '.mrc')
xml_writer = MARC::XMLWriter.new("#{filename}.xml")
writer = MARC::Writer.new("#{filename}.mrc")
collection_works.keys.sort.each do |key|
work = collection_works[key]
xml_writer.write(work.marc.entry)
Expand Down
2 changes: 1 addition & 1 deletion config/environments/production.rb
Expand Up @@ -86,7 +86,7 @@
# config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name')

if ENV["RAILS_LOG_TO_STDOUT"].present?
logger = ActiveSupport::Logger.new(STDOUT)
logger = ActiveSupport::Logger.new($stdout)
logger.formatter = config.log_formatter
config.logger = ActiveSupport::TaggedLogging.new(logger)
end
Expand Down
2 changes: 1 addition & 1 deletion spec/models/identifier_spec.rb
Expand Up @@ -8,7 +8,7 @@
it 'is a checkpoint resource' do
expect(identifier.resource_type).to eq(:Identifier)
expect(identifier.resource_id).to eq(identifier.id)
expect(identifier.resource_token).to eq(identifier.resource_type.to_s + ':' + identifier.resource_id.to_s)
expect(identifier.resource_token).to eq("#{identifier.resource_type}:#{identifier.resource_id}")
end

it do
Expand Down
4 changes: 2 additions & 2 deletions spec/models/uuid_spec.rb
Expand Up @@ -129,7 +129,7 @@
it 'is a checkpoint resource' do
expect(uuid.resource_type).to eq(:Uuid)
expect(uuid.resource_id).to eq(uuid.id)
expect(uuid.resource_token).to eq(uuid.resource_type.to_s + ':' + uuid.resource_id.to_s)
expect(uuid.resource_token).to eq("#{uuid.resource_type}:#{uuid.resource_id}")
end
end

Expand Down Expand Up @@ -161,7 +161,7 @@
expect(UuidIdentifier.count).to eq(index + 1)
end

identifiers.each_with_index do |identifier, index|
identifiers.each_with_index do |identifier, index| # rubocop:disable Style/CombinableLoops
expect(uuid.update?).to be false
expect(uuid.destroy?).to be false
expect(uuid.identifiers.count).to eq(n - index)
Expand Down
54 changes: 27 additions & 27 deletions spec/programs/assemble_marc_files/assemble_marc_files_spec.rb
Expand Up @@ -130,7 +130,7 @@
subject(:create_selection_marc_delta_files) { program.create_selection_marc_delta_files(selection) }

let(:today) { Time.now }
let(:filename) { selection.name + '_update_' + format("%04d-%02d-%02d", today.year, today.month, 15) }
let(:filename) { "#{selection.name}_update_#{format('%04d-%02d-%02d', today.year, today.month, 15)}" }
let(:writer) { instance_double(MARC::Writer, 'writer') }
let(:xml_writer) { instance_double(MARC::XMLWriter, 'xml_writer') }

Expand Down Expand Up @@ -237,12 +237,12 @@
[
'.',
'..',
selection.name + '.mrc',
selection.name + '.xml',
selection.name + format("-%02d", month) + '.mrc',
selection.name + format("-%02d", month) + '.xml',
collection.name + '_Complete.mrc',
collection.name + '_Complete.xml'
"#{selection.name}.mrc",
"#{selection.name}.xml",
"#{selection.name}#{format('-%02d', month)}.mrc",
"#{selection.name}#{format('-%02d', month)}.xml",
"#{collection.name}_Complete.mrc",
"#{collection.name}_Complete.xml"
]
end

Expand All @@ -254,12 +254,12 @@
expect(upload_marc_files).to match_array ["#{selection_name}.xml", "#{selection_name}.mrc", "#{selection_name}-#{month_string}.xml", "#{selection_name}-#{month_string}.mrc", "#{collection.name}_Complete.xml", "#{collection.name}_Complete.mrc"]
expect(collection).not_to have_received(:upload_marc_file).with('.')
expect(collection).not_to have_received(:upload_marc_file).with('..')
expect(collection).to have_received(:upload_marc_file).with(selection.name + '.mrc')
expect(collection).to have_received(:upload_marc_file).with(selection.name + '.xml')
expect(collection).to have_received(:upload_marc_file).with(selection.name + format("-%02d", month) + '.mrc')
expect(collection).to have_received(:upload_marc_file).with(selection.name + format("-%02d", month) + '.xml')
expect(collection).to have_received(:upload_marc_file).with(collection.name + '_Complete.mrc')
expect(collection).to have_received(:upload_marc_file).with(collection.name + '_Complete.xml')
expect(collection).to have_received(:upload_marc_file).with("#{selection.name}.mrc")
expect(collection).to have_received(:upload_marc_file).with("#{selection.name}.xml")
expect(collection).to have_received(:upload_marc_file).with("#{selection.name}#{format('-%02d', month)}.mrc")
expect(collection).to have_received(:upload_marc_file).with("#{selection.name}#{format('-%02d', month)}.xml")
expect(collection).to have_received(:upload_marc_file).with("#{collection.name}_Complete.mrc")
expect(collection).to have_received(:upload_marc_file).with("#{collection.name}_Complete.xml")
expect(program.errors).to be_empty
end

Expand All @@ -274,32 +274,32 @@
expect(upload_marc_files).to be_empty
expect(collection).not_to have_received(:upload_marc_file).with('.')
expect(collection).not_to have_received(:upload_marc_file).with('..')
expect(collection).not_to have_received(:upload_marc_file).with(selection.name + '.mrc')
expect(collection).not_to have_received(:upload_marc_file).with(selection.name + '.xml')
expect(collection).not_to have_received(:upload_marc_file).with(selection.name + format("-%02d", month) + '.mrc')
expect(collection).not_to have_received(:upload_marc_file).with(selection.name + format("-%02d", month) + '.xml')
expect(collection).not_to have_received(:upload_marc_file).with(collection.name + '_Complete.mrc')
expect(collection).not_to have_received(:upload_marc_file).with(collection.name + '_Complete.xml')
expect(collection).not_to have_received(:upload_marc_file).with("#{selection.name}.mrc")
expect(collection).not_to have_received(:upload_marc_file).with("#{selection.name}.xml")
expect(collection).not_to have_received(:upload_marc_file).with("#{selection.name}#{format('-%02d', month)}.mrc")
expect(collection).not_to have_received(:upload_marc_file).with("#{selection.name}#{format('-%02d', month)}.xml")
expect(collection).not_to have_received(:upload_marc_file).with("#{collection.name}_Complete.mrc")
expect(collection).not_to have_received(:upload_marc_file).with("#{collection.name}_Complete.xml")
expect(program.errors).to be_empty
end
end

context 'when upload error' do
before do
allow(collection).to receive(:upload_marc_file).with(collection.name + '_Complete.mrc').and_raise(StandardError)
allow(collection).to receive(:upload_marc_file).with("#{collection.name}_Complete.mrc").and_raise(StandardError)
end

it do
expect(upload_marc_files).to match_array ["#{selection_name}.xml", "#{selection_name}.mrc", "#{selection_name}-#{month_string}.xml", "#{selection_name}-#{month_string}.mrc", "#{collection.name}_Complete.xml"]
expect(collection).not_to have_received(:upload_marc_file).with('.')
expect(collection).not_to have_received(:upload_marc_file).with('..')
expect(collection).to have_received(:upload_marc_file).with(selection.name + '.mrc')
expect(collection).to have_received(:upload_marc_file).with(selection.name + '.xml')
expect(collection).to have_received(:upload_marc_file).with(selection.name + format("-%02d", month) + '.mrc')
expect(collection).to have_received(:upload_marc_file).with(selection.name + format("-%02d", month) + '.xml')
expect(collection).to have_received(:upload_marc_file).with(collection.name + '_Complete.mrc')
expect(collection).to have_received(:upload_marc_file).with(collection.name + '_Complete.xml')
expect(program.errors).to contain_exactly("ERROR Uploading #{collection.name + '_Complete.mrc'} StandardError")
expect(collection).to have_received(:upload_marc_file).with("#{selection.name}.mrc")
expect(collection).to have_received(:upload_marc_file).with("#{selection.name}.xml")
expect(collection).to have_received(:upload_marc_file).with("#{selection.name}#{format('-%02d', month)}.mrc")
expect(collection).to have_received(:upload_marc_file).with("#{selection.name}#{format('-%02d', month)}.xml")
expect(collection).to have_received(:upload_marc_file).with("#{collection.name}_Complete.mrc")
expect(collection).to have_received(:upload_marc_file).with("#{collection.name}_Complete.xml")
expect(program.errors).to contain_exactly("ERROR Uploading #{"#{collection.name}_Complete.mrc"} StandardError")
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions spec/services/ftp/file_spec.rb
Expand Up @@ -9,7 +9,7 @@
let(:pathname) { File.join(dirname, filename) }
let(:dirname) { 'dir' }
let(:extension) { 'ext' }
let(:filename) { 'file' + '.' + extension }
let(:filename) { "file.#{extension}" }
let(:facts) { { 'type' => 'file', 'modify' => Time.now.to_s } }

describe '#null_file' do
Expand All @@ -29,7 +29,7 @@
describe '#extension' do
subject { file.extension }

it { is_expected.to eq('.' + extension) }
it { is_expected.to eq(".#{extension}") }
end

describe '#updated' do
Expand Down

0 comments on commit 8f16fc9

Please sign in to comment.