Class: I18nFlow::Repository
- Inherits:
-
Object
- Object
- I18nFlow::Repository
- Defined in:
- lib/i18n_flow/repository.rb
Instance Method Summary collapse
- #asts_by_path ⇒ Object
- #asts_by_scope ⇒ Object
- #file_paths ⇒ Object
-
#initialize(base_path:, glob_patterns:) ⇒ Repository
constructor
A new instance of Repository.
Constructor Details
#initialize(base_path:, glob_patterns:) ⇒ Repository
Returns a new instance of Repository.
6 7 8 9 10 11 12 |
# File 'lib/i18n_flow/repository.rb', line 6 def initialize( base_path:, glob_patterns: ) @base_path = Pathname.new(base_path) @glob_patterns = glob_patterns.to_a end |
Instance Method Details
#asts_by_path ⇒ Object
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/i18n_flow/repository.rb', line 19 def asts_by_path @asts ||= file_paths .map { |path| rel_path = Pathname.new(path).relative_path_from(@base_path).to_s parser = I18nFlow::Parser.new(File.read(path), file_path: rel_path) parser.parse! [rel_path, parser.root_proxy] } .to_h end |
#asts_by_scope ⇒ Object
30 31 32 33 34 35 36 37 38 |
# File 'lib/i18n_flow/repository.rb', line 30 def asts_by_scope @asts_by_scope ||= Hash.new { |h, k| h[k] = {} } .tap { |h| asts_by_path.each { |path, tree| locale, *scopes = I18nFlow::Util.filepath_to_scope(path) h[scopes.join('.')][locale] = tree } } end |
#file_paths ⇒ Object
14 15 16 17 |
# File 'lib/i18n_flow/repository.rb', line 14 def file_paths @file_paths ||= @glob_patterns .flat_map { |pattern| Dir.glob(@base_path.join(pattern)) } end |