rosette-core 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +26 -0
- data/History.txt +3 -0
- data/README.md +94 -0
- data/Rakefile +18 -0
- data/lib/rosette/core.rb +110 -0
- data/lib/rosette/core/branch_utils.rb +152 -0
- data/lib/rosette/core/commands.rb +139 -0
- data/lib/rosette/core/commands/errors.rb +17 -0
- data/lib/rosette/core/commands/git/commit_command.rb +65 -0
- data/lib/rosette/core/commands/git/diff_base_command.rb +301 -0
- data/lib/rosette/core/commands/git/diff_command.rb +188 -0
- data/lib/rosette/core/commands/git/diff_entry.rb +44 -0
- data/lib/rosette/core/commands/git/fetch_command.rb +27 -0
- data/lib/rosette/core/commands/git/repo_snapshot_command.rb +40 -0
- data/lib/rosette/core/commands/git/show_command.rb +70 -0
- data/lib/rosette/core/commands/git/snapshot_command.rb +50 -0
- data/lib/rosette/core/commands/git/status_command.rb +128 -0
- data/lib/rosette/core/commands/git/with_non_merge_ref.rb +48 -0
- data/lib/rosette/core/commands/git/with_ref.rb +92 -0
- data/lib/rosette/core/commands/git/with_refs.rb +92 -0
- data/lib/rosette/core/commands/git/with_repo_name.rb +50 -0
- data/lib/rosette/core/commands/git/with_snapshots.rb +45 -0
- data/lib/rosette/core/commands/queuing/enqueue_commit_command.rb +37 -0
- data/lib/rosette/core/commands/queuing/requeue_commit_command.rb +46 -0
- data/lib/rosette/core/commands/translations/export_command.rb +257 -0
- data/lib/rosette/core/commands/translations/translation_lookup_command.rb +66 -0
- data/lib/rosette/core/commands/translations/with_locale.rb +47 -0
- data/lib/rosette/core/configurator.rb +160 -0
- data/lib/rosette/core/error_reporters/buffered_error_reporter.rb +96 -0
- data/lib/rosette/core/error_reporters/error_reporter.rb +31 -0
- data/lib/rosette/core/error_reporters/nil_error_reporter.rb +25 -0
- data/lib/rosette/core/error_reporters/printing_error_reporter.rb +58 -0
- data/lib/rosette/core/error_reporters/raising_error_reporter.rb +27 -0
- data/lib/rosette/core/errors.rb +93 -0
- data/lib/rosette/core/extractor/commit_log.rb +33 -0
- data/lib/rosette/core/extractor/commit_log_status.rb +57 -0
- data/lib/rosette/core/extractor/commit_processor.rb +109 -0
- data/lib/rosette/core/extractor/extractor.rb +72 -0
- data/lib/rosette/core/extractor/extractor_config.rb +74 -0
- data/lib/rosette/core/extractor/locale.rb +118 -0
- data/lib/rosette/core/extractor/phrase.rb +76 -0
- data/lib/rosette/core/extractor/phrase/phrase_index_policy.rb +108 -0
- data/lib/rosette/core/extractor/phrase/phrase_to_hash.rb +33 -0
- data/lib/rosette/core/extractor/repo_config.rb +339 -0
- data/lib/rosette/core/extractor/serializer_config.rb +55 -0
- data/lib/rosette/core/extractor/static_extractor.rb +44 -0
- data/lib/rosette/core/extractor/translation.rb +44 -0
- data/lib/rosette/core/extractor/translation/translation_to_hash.rb +28 -0
- data/lib/rosette/core/git/diff_finder.rb +131 -0
- data/lib/rosette/core/git/ref.rb +116 -0
- data/lib/rosette/core/git/repo.rb +378 -0
- data/lib/rosette/core/path_matcher_factory.rb +330 -0
- data/lib/rosette/core/resolvers/extractor_id.rb +37 -0
- data/lib/rosette/core/resolvers/integration_id.rb +37 -0
- data/lib/rosette/core/resolvers/preprocessor_id.rb +38 -0
- data/lib/rosette/core/resolvers/resolver.rb +115 -0
- data/lib/rosette/core/resolvers/serializer_id.rb +37 -0
- data/lib/rosette/core/snapshots/cached_head_snapshot_factory.rb +51 -0
- data/lib/rosette/core/snapshots/cached_snapshot_factory.rb +67 -0
- data/lib/rosette/core/snapshots/head_snapshot_factory.rb +58 -0
- data/lib/rosette/core/snapshots/repo_config_path_filter.rb +83 -0
- data/lib/rosette/core/snapshots/snapshot_factory.rb +184 -0
- data/lib/rosette/core/string_utils.rb +23 -0
- data/lib/rosette/core/translation_status.rb +81 -0
- data/lib/rosette/core/validators.rb +18 -0
- data/lib/rosette/core/validators/commit_validator.rb +62 -0
- data/lib/rosette/core/validators/commits_validator.rb +32 -0
- data/lib/rosette/core/validators/encoding_validator.rb +32 -0
- data/lib/rosette/core/validators/locale_validator.rb +37 -0
- data/lib/rosette/core/validators/repo_validator.rb +33 -0
- data/lib/rosette/core/validators/serializer_validator.rb +37 -0
- data/lib/rosette/core/validators/validator.rb +31 -0
- data/lib/rosette/core/version.rb +8 -0
- data/lib/rosette/data_stores.rb +11 -0
- data/lib/rosette/data_stores/errors.rb +26 -0
- data/lib/rosette/data_stores/phrase_status.rb +59 -0
- data/lib/rosette/integrations.rb +12 -0
- data/lib/rosette/integrations/errors.rb +15 -0
- data/lib/rosette/integrations/integratable.rb +58 -0
- data/lib/rosette/integrations/integration.rb +23 -0
- data/lib/rosette/preprocessors.rb +11 -0
- data/lib/rosette/preprocessors/errors.rb +14 -0
- data/lib/rosette/preprocessors/preprocessor.rb +48 -0
- data/lib/rosette/queuing.rb +14 -0
- data/lib/rosette/queuing/commits.rb +19 -0
- data/lib/rosette/queuing/commits/commit_conductor.rb +90 -0
- data/lib/rosette/queuing/commits/commit_job.rb +93 -0
- data/lib/rosette/queuing/commits/commits_queue_configurator.rb +60 -0
- data/lib/rosette/queuing/commits/extract_stage.rb +46 -0
- data/lib/rosette/queuing/commits/fetch_stage.rb +51 -0
- data/lib/rosette/queuing/commits/finalize_stage.rb +76 -0
- data/lib/rosette/queuing/commits/phrase_storage_granularity.rb +20 -0
- data/lib/rosette/queuing/commits/push_stage.rb +91 -0
- data/lib/rosette/queuing/commits/stage.rb +96 -0
- data/lib/rosette/queuing/job.rb +74 -0
- data/lib/rosette/queuing/queue.rb +28 -0
- data/lib/rosette/queuing/queue_configurator.rb +76 -0
- data/lib/rosette/queuing/worker.rb +30 -0
- data/lib/rosette/serializers.rb +10 -0
- data/lib/rosette/serializers/serializer.rb +98 -0
- data/lib/rosette/tms.rb +9 -0
- data/lib/rosette/tms/repository.rb +95 -0
- data/rosette-core.gemspec +24 -0
- data/spec/core/branch_utils_spec.rb +110 -0
- data/spec/core/commands/git/commit_command_spec.rb +60 -0
- data/spec/core/commands/git/diff_command_spec.rb +263 -0
- data/spec/core/commands/git/fetch_command_spec.rb +61 -0
- data/spec/core/commands/git/repo_snapshot_command_spec.rb +72 -0
- data/spec/core/commands/git/show_command_spec.rb +128 -0
- data/spec/core/commands/git/snapshot_command_spec.rb +86 -0
- data/spec/core/commands/git/status_command_spec.rb +154 -0
- data/spec/core/commands/queuing/enqueue_commit_command_spec.rb +34 -0
- data/spec/core/commands/queuing/requeue_commit_command_spec.rb +46 -0
- data/spec/core/commands/translations/export_command_spec.rb +113 -0
- data/spec/core/commands/translations/translation_lookup_command_spec.rb +58 -0
- data/spec/core/configurator_spec.rb +47 -0
- data/spec/core/error_reporters/buffered_error_reporter_spec.rb +61 -0
- data/spec/core/error_reporters/nil_error_reporter_spec.rb +16 -0
- data/spec/core/error_reporters/printing_error_reporter_spec.rb +60 -0
- data/spec/core/extractor/commit_log_status_spec.rb +216 -0
- data/spec/core/extractor/commit_processor_spec.rb +68 -0
- data/spec/core/extractor/extractor_config_spec.rb +47 -0
- data/spec/core/extractor/extractor_spec.rb +26 -0
- data/spec/core/extractor/locale_spec.rb +92 -0
- data/spec/core/extractor/phrase/phrase_index_policy_spec.rb +116 -0
- data/spec/core/extractor/phrase/phrase_to_hash_spec.rb +18 -0
- data/spec/core/extractor/repo_config_spec.rb +147 -0
- data/spec/core/extractor/translation/translation_to_hash_spec.rb +25 -0
- data/spec/core/git/diff_finder_spec.rb +74 -0
- data/spec/core/git/ref_spec.rb +118 -0
- data/spec/core/git/repo_spec.rb +216 -0
- data/spec/core/path_matcher_factory_spec.rb +139 -0
- data/spec/core/resolvers/extractor_id_spec.rb +47 -0
- data/spec/core/resolvers/integration_id_spec.rb +47 -0
- data/spec/core/resolvers/preprocessor_id_spec.rb +47 -0
- data/spec/core/resolvers/serializer_id_spec.rb +47 -0
- data/spec/core/snapshots/snapshot_factory_spec.rb +145 -0
- data/spec/core/string_utils_spec.rb +19 -0
- data/spec/core/translation_status_spec.rb +91 -0
- data/spec/core/validators/commit_validator_spec.rb +40 -0
- data/spec/core/validators/encoding_validator_spec.rb +30 -0
- data/spec/core/validators/locale_validator_spec.rb +31 -0
- data/spec/core/validators/repo_validator_spec.rb +30 -0
- data/spec/core/validators/serializer_validator_spec.rb +31 -0
- data/spec/integrations/integratable_spec.rb +58 -0
- data/spec/queuing/commits/commit_conductor_spec.rb +71 -0
- data/spec/queuing/commits/commit_job_spec.rb +87 -0
- data/spec/queuing/commits/extract_stage_spec.rb +68 -0
- data/spec/queuing/commits/fetch_stage_spec.rb +101 -0
- data/spec/queuing/commits/finalize_stage_spec.rb +88 -0
- data/spec/queuing/commits/push_stage_spec.rb +145 -0
- data/spec/queuing/commits/stage_spec.rb +80 -0
- data/spec/queuing/job_spec.rb +33 -0
- data/spec/queuing/queue_configurator_spec.rb +44 -0
- data/spec/spec_helper.rb +90 -0
- data/spec/test_helpers/fake_commit_stage.rb +17 -0
- metadata +257 -0
@@ -0,0 +1,23 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
module Rosette
|
4
|
+
module Core
|
5
|
+
|
6
|
+
# General-purpose string manipulation utilities.
|
7
|
+
class StringUtils
|
8
|
+
class << self
|
9
|
+
# Converts a snake_cased string into a CamelCased one.
|
10
|
+
#
|
11
|
+
# @example
|
12
|
+
# StringUtils.camelize('foo_bar') # => "FooBar"
|
13
|
+
#
|
14
|
+
# @param [String] str The snake_cased string to convert.
|
15
|
+
# @return [String]
|
16
|
+
def camelize(str)
|
17
|
+
str.gsub(/(^\w|[-_]\w)/) { $1[-1].upcase }
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
module Rosette
|
4
|
+
module Core
|
5
|
+
|
6
|
+
# A utility class that encapsulates how translated a set of phrases is.
|
7
|
+
# The class knows how to report translation percentages, etc.
|
8
|
+
#
|
9
|
+
# @!attribute [r] phrase_count
|
10
|
+
# @return [Fixnum] the total number of phrases.
|
11
|
+
# @!attribute [r] locale_counts
|
12
|
+
# @return [Hash<Fixnum>] a hash of locale codes to counts. Each count
|
13
|
+
# represents the number of completed translations for that locale.
|
14
|
+
class TranslationStatus
|
15
|
+
attr_reader :phrase_count, :locale_counts
|
16
|
+
|
17
|
+
# Creates a new instance.
|
18
|
+
#
|
19
|
+
# @param [Fixnum] phrase_count The total number of phrases.
|
20
|
+
# @return [TranslationStatus]
|
21
|
+
def initialize(phrase_count)
|
22
|
+
@phrase_count = phrase_count
|
23
|
+
@locale_counts = {}
|
24
|
+
end
|
25
|
+
|
26
|
+
# Adds a locale code and count pair. The count should be the total number
|
27
|
+
# of completed translations in the locale.
|
28
|
+
#
|
29
|
+
# @param [String] locale_code
|
30
|
+
# @param [Fixnum] count
|
31
|
+
# @return [void]
|
32
|
+
def add_locale_count(locale_code, count)
|
33
|
+
locale_counts[locale_code] = count
|
34
|
+
end
|
35
|
+
|
36
|
+
# Returns true if the given locale is fully translated (i.e. the number of
|
37
|
+
# translations is greater than or equal to the number of phrases).
|
38
|
+
#
|
39
|
+
# @param [String] locale_code
|
40
|
+
# @return [Boolean]
|
41
|
+
def fully_translated_in?(locale_code)
|
42
|
+
(locale_counts[locale_code] || -1) >= phrase_count
|
43
|
+
end
|
44
|
+
|
45
|
+
# Returns true if every locale is fully translated, false otherwise.
|
46
|
+
#
|
47
|
+
# @return [Boolean]
|
48
|
+
def fully_translated?
|
49
|
+
locale_counts.all? do |locale_code, _|
|
50
|
+
fully_translated_in?(locale_code)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
# Retrieves the number of completed translations for the given locale.
|
55
|
+
# Use this method in combination with +add_locale_count+.
|
56
|
+
def locale_count(locale_code)
|
57
|
+
locale_counts[locale_code]
|
58
|
+
end
|
59
|
+
|
60
|
+
# Retrieves a list of all the added locales.
|
61
|
+
#
|
62
|
+
# @return [Array<String>]
|
63
|
+
def locales
|
64
|
+
locale_counts.keys
|
65
|
+
end
|
66
|
+
|
67
|
+
# Calculates a translated percentage for the given locale.
|
68
|
+
#
|
69
|
+
# @param [String] locale_code
|
70
|
+
# @param [Fixnum] precision The precision to use when rounding the
|
71
|
+
# percentage.
|
72
|
+
# @return [Float] the translation percentage, rounded to +precision+
|
73
|
+
# decimal places.
|
74
|
+
def percent_translated(locale_code, precision = 2)
|
75
|
+
pct = locale_counts[locale_code] / phrase_count.to_f
|
76
|
+
[1.0, pct.round(precision)].min
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
81
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
module Rosette
|
4
|
+
module Core
|
5
|
+
|
6
|
+
# Contains validators for validating the parameters of Rosette's commands.
|
7
|
+
module Validators
|
8
|
+
autoload :Validator, 'rosette/core/validators/validator'
|
9
|
+
autoload :CommitValidator, 'rosette/core/validators/commit_validator'
|
10
|
+
autoload :CommitsValidator, 'rosette/core/validators/commits_validator'
|
11
|
+
autoload :RepoValidator, 'rosette/core/validators/repo_validator'
|
12
|
+
autoload :SerializerValidator, 'rosette/core/validators/serializer_validator'
|
13
|
+
autoload :LocaleValidator, 'rosette/core/validators/locale_validator'
|
14
|
+
autoload :EncodingValidator, 'rosette/core/validators/encoding_validator'
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
module Rosette
|
4
|
+
module Core
|
5
|
+
module Validators
|
6
|
+
|
7
|
+
# Validates the existence of a commit.
|
8
|
+
#
|
9
|
+
# @example
|
10
|
+
# v = CommitValidator.new
|
11
|
+
# v.valid?('73cd130a42017d794ffa86ef0d255541d518a7b3', 'my_repo', config)
|
12
|
+
# # => true
|
13
|
+
#
|
14
|
+
# v.valid?('non-existent-ref', 'my_repo', config)
|
15
|
+
# # => false
|
16
|
+
#
|
17
|
+
# v.messages # => ["Unable to find commit 'non-existent-ref'."]
|
18
|
+
class CommitValidator < Validator
|
19
|
+
# Returns true if the commit is valid, false otherwise. Also returns false if
|
20
|
+
# +repo_name+ isn't a valid repo configured in +configuration+.
|
21
|
+
#
|
22
|
+
# @param [String] commit_str The commit to validate.
|
23
|
+
# @param [String] repo_name The repo to look for +commit_str+ in.
|
24
|
+
# @param [Configurator] configuration The Rosette configuration to use.
|
25
|
+
# @return [Boolean]
|
26
|
+
def valid?(commit_str, repo_name, configuration)
|
27
|
+
if repo_config = configuration.get_repo(repo_name)
|
28
|
+
if commit_str
|
29
|
+
commit = repo_config.repo.get_rev_commit(commit_str)
|
30
|
+
validate_commit(commit)
|
31
|
+
else
|
32
|
+
messages << "Nil commit passed."
|
33
|
+
false
|
34
|
+
end
|
35
|
+
else
|
36
|
+
messages << "Unable to find repo #{repo_name}."
|
37
|
+
false
|
38
|
+
end
|
39
|
+
rescue Java::OrgEclipseJgitErrors::MissingObjectException, Java::JavaLang::IllegalArgumentException
|
40
|
+
messages << "Unable to find commit '#{commit_str}'."
|
41
|
+
false
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def validate_commit(commit)
|
47
|
+
if options.fetch(:allow_merge_commit, true)
|
48
|
+
true
|
49
|
+
else
|
50
|
+
if commit.getParentCount > 1
|
51
|
+
messages << "Unable to validate #{commit.getId.name} because it's a merge commit."
|
52
|
+
false
|
53
|
+
else
|
54
|
+
true
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
module Rosette
|
4
|
+
module Core
|
5
|
+
module Validators
|
6
|
+
|
7
|
+
# Validates the existence of an array of commits.
|
8
|
+
#
|
9
|
+
# @example
|
10
|
+
# v = CommitsValidator.new
|
11
|
+
# v.valid?(['73cd130a42017d794ffa86ef0d255541d518a7b3'], 'my_repo', config)
|
12
|
+
# # => true
|
13
|
+
#
|
14
|
+
# v.valid?(['non-existent-ref'], 'my_repo', config)
|
15
|
+
# # => false
|
16
|
+
#
|
17
|
+
# v.messages # => ["Unable to find commit 'non-existent-ref'."]
|
18
|
+
class CommitsValidator < CommitValidator
|
19
|
+
def valid?(commit_strs, repo_name, configuration)
|
20
|
+
if commit_strs
|
21
|
+
commit_strs.all? do |commit_str|
|
22
|
+
super(commit_str, repo_name, configuration)
|
23
|
+
end
|
24
|
+
else
|
25
|
+
false
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
module Rosette
|
4
|
+
module Core
|
5
|
+
module Validators
|
6
|
+
|
7
|
+
# Validates an encoding.
|
8
|
+
#
|
9
|
+
# @example
|
10
|
+
# v = EncodingValidator.new
|
11
|
+
# v.valid?(Encoding::UTF_8, nil, nil) # => true
|
12
|
+
# v.valid?('foo', nil, nil) # => false
|
13
|
+
# v.messages # => ["Encoding 'foo' was not recognized."]
|
14
|
+
class EncodingValidator < Validator
|
15
|
+
# Returns true if the encoding is valid, false otherwise.
|
16
|
+
#
|
17
|
+
# @param [String, Encoding] encoding The encoding to validate.
|
18
|
+
# @param [String] repo_name (not used)
|
19
|
+
# @param [Configurator] configuration (not used)
|
20
|
+
# @return [Boolean]
|
21
|
+
def valid?(encoding, repo_name, configuration)
|
22
|
+
Encoding.find(encoding)
|
23
|
+
true
|
24
|
+
rescue ArgumentError
|
25
|
+
messages << "Encoding '#{encoding}' was not recognized."
|
26
|
+
false
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
module Rosette
|
4
|
+
module Core
|
5
|
+
module Validators
|
6
|
+
|
7
|
+
# Validates a locale by making sure the given repo has been configured
|
8
|
+
# to support it.
|
9
|
+
#
|
10
|
+
# @example
|
11
|
+
# v = LocaleValidator.new
|
12
|
+
# v.valid?('ko-KR', 'my_repo', config) # => true
|
13
|
+
# v.valid?('foo-BAR', 'my_repo', config) # => false
|
14
|
+
# v.messages # => ["Repo 'my_repo' doesn't support the 'foo-BAR' locale"]
|
15
|
+
class LocaleValidator < Validator
|
16
|
+
# Returns true if the locale is valid, false otherwise.
|
17
|
+
#
|
18
|
+
# @param [String] locale_code The locale to validate.
|
19
|
+
# @param [String] repo_name The repo to use. This method checks the
|
20
|
+
# entry in +configuration+ for +repo_name+ to see if it supports
|
21
|
+
# +locale_code+.
|
22
|
+
# @param [Configurator] configuration The Rosette configuration to use.
|
23
|
+
# @return [Boolean]
|
24
|
+
def valid?(locale_code, repo_name, configuration)
|
25
|
+
repo = configuration.get_repo(repo_name)
|
26
|
+
if locale_code && repo.get_locale(locale_code)
|
27
|
+
true
|
28
|
+
else
|
29
|
+
messages << "Repo '#{repo_name}' doesn't support the '#{locale_code}' locale"
|
30
|
+
false
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
module Rosette
|
4
|
+
module Core
|
5
|
+
module Validators
|
6
|
+
|
7
|
+
# Validates a repo by making sure it has been configured.
|
8
|
+
#
|
9
|
+
# @example
|
10
|
+
# v = RepoValidator.new
|
11
|
+
# v.valid?('my_repo', nil, config) # => true
|
12
|
+
# v.valid?('bad_repo', nil, config) # => false
|
13
|
+
# v.messages # => ["Unable to find repo 'bad_repo'."]
|
14
|
+
class RepoValidator < Validator
|
15
|
+
# Returns true if the repo is valid, false otherwise
|
16
|
+
#
|
17
|
+
# @param [String] repo_name The repo to validate.
|
18
|
+
# @param [String] _ (not used)
|
19
|
+
# @param [Configurator] configuration The Rosette configuration to use.
|
20
|
+
# @return [Boolean]
|
21
|
+
def valid?(repo_name, _, configuration)
|
22
|
+
if !configuration.get_repo(repo_name)
|
23
|
+
messages << "Unable to find repo '#{repo_name}'."
|
24
|
+
false
|
25
|
+
else
|
26
|
+
true
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
module Rosette
|
4
|
+
module Core
|
5
|
+
module Validators
|
6
|
+
|
7
|
+
# Validates a serializer by making sure the given repo has been configured
|
8
|
+
# to support it.
|
9
|
+
#
|
10
|
+
# @example
|
11
|
+
# v = SerializerValidator.new
|
12
|
+
# v.valid?('yaml/rails', 'my_repo', config) # => true
|
13
|
+
# v.valid?('yaml/blarg', 'my_repo', config) # => false
|
14
|
+
# v.messages # => ["Unable to find serializer 'yaml/blarg'."]
|
15
|
+
class SerializerValidator < Validator
|
16
|
+
# Returns true if the serializer is valid, false otherwise.
|
17
|
+
#
|
18
|
+
# @param [String] serializer_id The serializer to validate.
|
19
|
+
# @param [String] repo_name The repo to use. This method checks the
|
20
|
+
# entry in +configuration+ for +repo_name+ to see if it supports
|
21
|
+
# +serializer_id+.
|
22
|
+
# @param [Configurator] configuration The Rosette configuration to use.
|
23
|
+
# @return [Boolean]
|
24
|
+
def valid?(serializer_id, repo_name, configuration)
|
25
|
+
repo = configuration.get_repo(repo_name)
|
26
|
+
if repo.get_serializer_config(serializer_id)
|
27
|
+
true
|
28
|
+
else
|
29
|
+
messages << "Unable to find serializer '#{serializer_id}'."
|
30
|
+
false
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
module Rosette
|
4
|
+
module Core
|
5
|
+
module Validators
|
6
|
+
|
7
|
+
# Base class for validators.
|
8
|
+
#
|
9
|
+
# @!attribute [r] options
|
10
|
+
# @return [Hash] a hash of options.
|
11
|
+
class Validator
|
12
|
+
attr_reader :options
|
13
|
+
|
14
|
+
# Creates a new validator.
|
15
|
+
#
|
16
|
+
# @param [Hash] options A hash of options.
|
17
|
+
def initialize(options = {})
|
18
|
+
@options = options
|
19
|
+
end
|
20
|
+
|
21
|
+
# An array of error messages. Populated when +#valid?+ is called.
|
22
|
+
#
|
23
|
+
# @return [Array<String>] The list of error messages.
|
24
|
+
def messages
|
25
|
+
@messages ||= []
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
module Rosette
|
4
|
+
module DataStores
|
5
|
+
|
6
|
+
# Errors that can be raised during data store operations.
|
7
|
+
module Errors
|
8
|
+
# Raised when an error occurs when adding a new translation.
|
9
|
+
class AddTranslationError < StandardError; end
|
10
|
+
|
11
|
+
# Raised when a phrase with the given attributes cannot be found.
|
12
|
+
class PhraseNotFoundError < StandardError; end
|
13
|
+
|
14
|
+
# Raised when the appropriate translation parameters aren't provided.
|
15
|
+
class MissingParamError < StandardError; end
|
16
|
+
|
17
|
+
# Raised when a commit log entry can't be updated.
|
18
|
+
class CommitLogUpdateError < StandardError; end
|
19
|
+
|
20
|
+
# Raised when one of the locale entries for a commit log can't be
|
21
|
+
# updated.
|
22
|
+
class CommitLogLocaleUpdateError < StandardError; end
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|