Class: FindT::Scanner

Inherits:
Object
  • Object
show all
Defined in:
lib/find_t/scanner.rb

Instance Method Summary collapse

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

#filesObject



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.expand_path @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