Class: FindT::Scanner
- Inherits:
-
Object
- Object
- FindT::Scanner
- Defined in:
- lib/find_t/scanner.rb
Instance Method Summary collapse
- #files ⇒ Object
-
#initialize(root_path:, rails: false) ⇒ Scanner
constructor
A new instance of Scanner.
- #scan(key) ⇒ Object
Constructor Details
#initialize(root_path:, rails: false) ⇒ Scanner
Returns a new instance of Scanner.
8 9 10 |
# File 'lib/find_t/scanner.rb', line 8 def initialize(root_path:, rails: false) @root_path, @rails = Pathname.new(root_path), rails end |
Instance Method Details
#files ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/find_t/scanner.rb', line 12 def files return @files if @files if @rails rails_env_file = File. @root_path.join('config', 'environment') if File.exists? rails_env_file require rails_env_file else raise RailsNotFoundError.new('Cannot find rails environment file') end @files = I18n.load_path else @files = Dir.glob @root_path.join('config', 'locales', '**', '*.{yaml,yml}') end @files end |
#scan(key) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/find_t/scanner.rb', line 32 def scan(key) return if !key || '' == key scopes = key.split('.').unshift nil founds = [] files.reverse.each do |file| founds += FileScanner.new(file).find scopes end founds end |