zizia 4.0.2.alpha.01 → 4.0.3.alpha.01
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- metadata +2 -28
- data/lib/zizia/always_invalid_validator.rb +0 -17
- data/lib/zizia/csv_template.rb +0 -9
- data/lib/zizia/engine.rb +0 -32
- data/lib/zizia/hash_mapper.rb +0 -44
- data/lib/zizia/hyrax/hyrax_basic_metadata_mapper.rb +0 -149
- data/lib/zizia/hyrax/hyrax_default_updater.rb +0 -11
- data/lib/zizia/hyrax/hyrax_delete_files_updater.rb +0 -16
- data/lib/zizia/hyrax/hyrax_metadata_only_updater.rb +0 -58
- data/lib/zizia/hyrax/hyrax_record_importer.rb +0 -247
- data/lib/zizia/hyrax/metadata_only_stack.rb +0 -70
- data/lib/zizia/importer.rb +0 -58
- data/lib/zizia/input_record.rb +0 -65
- data/lib/zizia/metadata_mapper.rb +0 -83
- data/lib/zizia/parser.rb +0 -132
- data/lib/zizia/parsers/csv_parser.rb +0 -45
- data/lib/zizia/record_importer.rb +0 -44
- data/lib/zizia/spec/fakes/fake_parser.rb +0 -22
- data/lib/zizia/spec/shared_examples/a_mapper.rb +0 -32
- data/lib/zizia/spec/shared_examples/a_parser.rb +0 -73
- data/lib/zizia/spec/shared_examples/a_validator.rb +0 -29
- data/lib/zizia/spec.rb +0 -14
- data/lib/zizia/validator.rb +0 -106
- data/lib/zizia/validators/csv_format_validator.rb +0 -26
- data/lib/zizia/validators/title_validator.rb +0 -30
- data/lib/zizia/version.rb +0 -5
- data/lib/zizia.rb +0 -66
data/lib/zizia/validator.rb
DELETED
@@ -1,106 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Zizia
|
4
|
-
##
|
5
|
-
# @abstract A null validator; always returns an empty error collection
|
6
|
-
#
|
7
|
-
# Validators are used to ensure the correctness of input to a parser. Each
|
8
|
-
# validator must respond to `#validate` and return a collection of errors
|
9
|
-
# found during validation. If the input is valid, this collection must be
|
10
|
-
# empty. Otherwise, it contains any number of `Validator::Error` structs
|
11
|
-
# which should be logged to Rails.logger by the validator.
|
12
|
-
#
|
13
|
-
# The validation process accepts an entire `Parser` and is free to inspect
|
14
|
-
# the input `#file` content, or view its individual `#records`.
|
15
|
-
#
|
16
|
-
# The base class provides infrastructure for the key behavior, relying on a
|
17
|
-
# private `#run_validation` method to provide the core behavior. In most cases
|
18
|
-
# implementers will want to simply override this method.
|
19
|
-
#
|
20
|
-
# @example validating a parser
|
21
|
-
# validator = MyValidator.new
|
22
|
-
# validator.validate(parser: myParser)
|
23
|
-
#
|
24
|
-
# @example validating an invalid parser
|
25
|
-
# validator = MyValidator.new
|
26
|
-
# validator.validate(parser: invalidParser)
|
27
|
-
# # => Error<#... validator: MyValidator,
|
28
|
-
# name: 'An Error Name',
|
29
|
-
# description: '...'
|
30
|
-
# lineno: 37>
|
31
|
-
#
|
32
|
-
# @example Implementing a custom Validator and using it in a Parser
|
33
|
-
# # Validator checks that the title, when downcased is equal to `moomin`
|
34
|
-
# class TitleIsMoominValidator
|
35
|
-
# def run_validation(parser:)
|
36
|
-
# parser.records.each_with_object([]) do |record, errors|
|
37
|
-
# errors << Error.new(self, :title_is_not_moomin) unless
|
38
|
-
# title_is_moomin?(record)
|
39
|
-
# end
|
40
|
-
# end
|
41
|
-
#
|
42
|
-
# def title_is_moomin?(record)
|
43
|
-
# return false unless record.respond_to?(:title)
|
44
|
-
# return true if record.title.downcase == 'moomin
|
45
|
-
# true
|
46
|
-
# end
|
47
|
-
# end
|
48
|
-
#
|
49
|
-
# parser = MyParser.new(some_content)
|
50
|
-
# parser.validations << TitleIsMoominvalidator.new
|
51
|
-
# parser.validate
|
52
|
-
# parser.valid? # => false (unless all the records match the title)
|
53
|
-
#
|
54
|
-
# @see Parser#validate
|
55
|
-
class Validator
|
56
|
-
##
|
57
|
-
# A representation of an error encountered in validation.
|
58
|
-
Error = Struct.new(:validator, :name, :description, :lineno) do
|
59
|
-
##
|
60
|
-
# @!attribute [rw] validator
|
61
|
-
# @return [#to_s] the validator that generated this error
|
62
|
-
# @!attribute [rw] name
|
63
|
-
# @return [#to_s] a short descriptive name for the given error
|
64
|
-
# @!attribute [rw] description
|
65
|
-
# @return [#to_s] a long form description or message
|
66
|
-
# @!attribute [rw] lineno
|
67
|
-
# @return [#to_s] the line number, or other indication of the location
|
68
|
-
# where the error was encountered
|
69
|
-
|
70
|
-
##
|
71
|
-
# @return [Boolean]
|
72
|
-
def validator_error?
|
73
|
-
true
|
74
|
-
end
|
75
|
-
|
76
|
-
##
|
77
|
-
# @return [String]
|
78
|
-
def to_s
|
79
|
-
"#{name}: #{description} (#{validator})"
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
##
|
84
|
-
# @param parser [Parser]
|
85
|
-
#
|
86
|
-
# @return [Enumerator<Error>] a collection of errors found in validation
|
87
|
-
def validate(parser:)
|
88
|
-
run_validation(parser: parser).tap do |errors|
|
89
|
-
errors.map { |error| Rails.logger.error "[zizia] #{error}" }
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
private
|
94
|
-
|
95
|
-
# rubocop:disable Lint/UnusedMethodArgument
|
96
|
-
|
97
|
-
##
|
98
|
-
# @return [Enumerator<Error>]
|
99
|
-
#
|
100
|
-
def run_validation(parser:)
|
101
|
-
[].to_enum
|
102
|
-
end
|
103
|
-
|
104
|
-
# rubocop:enable Lint/UnusedMethodArgument
|
105
|
-
end
|
106
|
-
end
|
@@ -1,26 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Zizia
|
4
|
-
##
|
5
|
-
# A validator for correctly formatted CSV.
|
6
|
-
#
|
7
|
-
# @example
|
8
|
-
# parser = Parser.new(file: File.open('path/to/my.csv'))
|
9
|
-
#
|
10
|
-
# CsvFormatValidator.new.validate(parser: parser)
|
11
|
-
#
|
12
|
-
# @see http://ruby-doc.org/stdlib-2.0.0/libdoc/csv/rdoc/CSV/MalformedCSVError.html
|
13
|
-
class CsvFormatValidator < Validator
|
14
|
-
##
|
15
|
-
# @private
|
16
|
-
#
|
17
|
-
# @see Validator#validate
|
18
|
-
def run_validation(parser:, **)
|
19
|
-
return [] if CSV.parse(parser.file.read)
|
20
|
-
rescue CSV::MalformedCSVError => e
|
21
|
-
[Error.new(self.class, e.class, e.message)]
|
22
|
-
ensure
|
23
|
-
parser.file.rewind
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
@@ -1,30 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Zizia
|
4
|
-
class TitleValidator < Validator
|
5
|
-
##
|
6
|
-
# @private
|
7
|
-
#
|
8
|
-
# @see Validator#validate
|
9
|
-
def run_validation(parser:, **)
|
10
|
-
parser.records.each_with_object([]) do |record, errors|
|
11
|
-
titles = record.respond_to?(:title) ? record.title : []
|
12
|
-
|
13
|
-
errors << error_for(record: record) if Array(titles).empty?
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
protected
|
18
|
-
|
19
|
-
##
|
20
|
-
# @private
|
21
|
-
# @param record [InputRecord]
|
22
|
-
#
|
23
|
-
# @return [Error]
|
24
|
-
def error_for(record:)
|
25
|
-
Error.new(self,
|
26
|
-
:missing_title,
|
27
|
-
"Title is required; got #{record.mapper.metadata}")
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
data/lib/zizia/version.rb
DELETED
data/lib/zizia.rb
DELETED
@@ -1,66 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "zizia/engine"
|
4
|
-
|
5
|
-
##
|
6
|
-
# Bulk object import for Samvera.
|
7
|
-
#
|
8
|
-
# == Importers
|
9
|
-
#
|
10
|
-
# {Importer} is the core class for importing records using {Zizia}.
|
11
|
-
# Importers accept a {Parser} and (optionally) a custom {RecordImporter}, and
|
12
|
-
# process each record in the given parser (see: {Parser#records}).
|
13
|
-
#
|
14
|
-
# @example Importing in bulk from a file
|
15
|
-
# parser = Zizia::Parser.for(file: File.new('path/to/file.ext'))
|
16
|
-
#
|
17
|
-
# Zizia::Importer.new(parser: parser).import if parser.validate
|
18
|
-
#
|
19
|
-
# @example A basic configuration
|
20
|
-
# Zizia.config do |config|
|
21
|
-
# end
|
22
|
-
#
|
23
|
-
module Zizia
|
24
|
-
##
|
25
|
-
# @yield the current configuration
|
26
|
-
# @yieldparam config [Zizia::Configuration]
|
27
|
-
#
|
28
|
-
# @return [Zizia::Configuration] the current configuration
|
29
|
-
def config
|
30
|
-
yield @configuration if block_given?
|
31
|
-
@configuration
|
32
|
-
end
|
33
|
-
module_function :config
|
34
|
-
|
35
|
-
require 'zizia/version'
|
36
|
-
require 'zizia/metadata_mapper'
|
37
|
-
require 'zizia/hash_mapper'
|
38
|
-
require 'zizia/hyrax/hyrax_basic_metadata_mapper'
|
39
|
-
require 'zizia/importer'
|
40
|
-
require 'zizia/record_importer'
|
41
|
-
require 'zizia/hyrax/hyrax_record_importer'
|
42
|
-
require 'zizia/input_record'
|
43
|
-
require 'zizia/validator'
|
44
|
-
require 'zizia/validators/csv_format_validator'
|
45
|
-
require 'zizia/validators/title_validator'
|
46
|
-
require 'zizia/parser'
|
47
|
-
require 'zizia/csv_template'
|
48
|
-
|
49
|
-
##
|
50
|
-
# Module-wide options for `Zizia`.
|
51
|
-
class Configuration
|
52
|
-
attr_accessor :metadata_mapper_class
|
53
|
-
|
54
|
-
def initialize
|
55
|
-
self.metadata_mapper_class = Zizia::HyraxBasicMetadataMapper
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
@configuration = Configuration.new
|
60
|
-
|
61
|
-
require 'zizia/parsers/csv_parser'
|
62
|
-
require 'zizia/hyrax/metadata_only_stack'
|
63
|
-
require 'zizia/hyrax/hyrax_metadata_only_updater'
|
64
|
-
require 'zizia/hyrax/hyrax_default_updater'
|
65
|
-
require 'zizia/hyrax/hyrax_delete_files_updater'
|
66
|
-
end
|