Class: I18nFlow::Validator::Multiplexer
- Inherits:
-
Object
- Object
- I18nFlow::Validator::Multiplexer
- Defined in:
- lib/i18n_flow/validator/multiplexer.rb
Instance Attribute Summary collapse
-
#linters ⇒ Object
readonly
Returns the value of attribute linters.
-
#locale_pairs ⇒ Object
readonly
Returns the value of attribute locale_pairs.
-
#repository ⇒ Object
readonly
Returns the value of attribute repository.
-
#valid_locales ⇒ Object
readonly
Returns the value of attribute valid_locales.
Instance Method Summary collapse
- #errors ⇒ Object
-
#initialize(repository:, valid_locales:, locale_pairs:, linters: %i[file_scope symmetry]) ⇒ Multiplexer
constructor
A new instance of Multiplexer.
- #validate! ⇒ Object
Constructor Details
#initialize(repository:, valid_locales:, locale_pairs:, linters: %i[file_scope symmetry]) ⇒ Multiplexer
Returns a new instance of Multiplexer.
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/i18n_flow/validator/multiplexer.rb', line 12 def initialize( repository:, valid_locales:, locale_pairs:, linters: %i[file_scope symmetry] ) @repository = repository @valid_locales = valid_locales @locale_pairs = locale_pairs @linters = linters end |
Instance Attribute Details
#linters ⇒ Object (readonly)
Returns the value of attribute linters.
10 11 12 |
# File 'lib/i18n_flow/validator/multiplexer.rb', line 10 def linters @linters end |
#locale_pairs ⇒ Object (readonly)
Returns the value of attribute locale_pairs.
9 10 11 |
# File 'lib/i18n_flow/validator/multiplexer.rb', line 9 def locale_pairs @locale_pairs end |
#repository ⇒ Object (readonly)
Returns the value of attribute repository.
7 8 9 |
# File 'lib/i18n_flow/validator/multiplexer.rb', line 7 def repository @repository end |
#valid_locales ⇒ Object (readonly)
Returns the value of attribute valid_locales.
8 9 10 |
# File 'lib/i18n_flow/validator/multiplexer.rb', line 8 def valid_locales @valid_locales end |
Instance Method Details
#errors ⇒ Object
54 55 56 |
# File 'lib/i18n_flow/validator/multiplexer.rb', line 54 def errors @errors ||= Hash.new { |h, k| h[k] = {} } end |
#validate! ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/i18n_flow/validator/multiplexer.rb', line 24 def validate! @errors = nil if linters.include?(:file_scope) repository.asts_by_path.each do |path, tree| validator = FileScope.new(tree, filepath: path) validator.validate! validator.errors.each do |err| errors[err.file][err.key] = err end end end if linters.include?(:symmetry) repository.asts_by_scope.each do |scope, locale_trees| locale_pairs.each do |(master, slave)| master_tree = locale_trees[master] slave_tree = locale_trees[slave] next unless master_tree && slave_tree validator = Symmetry.new(master_tree[master], slave_tree[slave]) validator.validate! validator.errors.each do |err| errors[err.file][err.key] = err end end end end end |