Class: I18nliner::Processors::AbstractProcessor

Inherits:
Object
  • Object
show all
Defined in:
lib/i18nliner/processors/abstract_processor.rb

Direct Known Subclasses

RubyProcessor

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(translations, options = {}) ⇒ AbstractProcessor

Returns a new instance of AbstractProcessor.


10
11
12
13
14
15
16
17
# File 'lib/i18nliner/processors/abstract_processor.rb', line 10

def initialize(translations, options = {})
  @translations = translations
  @translation_count = 0
  @file_count = 0
  @only = options[:only]
  @checker = options[:checker] || method(:noop_checker)
  @pattern = options[:pattern] || self.class.default_pattern
end

Instance Attribute Details

#file_countObject (readonly)

Returns the value of attribute file_count


8
9
10
# File 'lib/i18nliner/processors/abstract_processor.rb', line 8

def file_count
  @file_count
end

#translation_countObject (readonly)

Returns the value of attribute translation_count


8
9
10
# File 'lib/i18nliner/processors/abstract_processor.rb', line 8

def translation_count
  @translation_count
end

Class Method Details

.default_pattern(*pattern) ⇒ Object


48
49
50
51
# File 'lib/i18nliner/processors/abstract_processor.rb', line 48

def self.default_pattern(*pattern)
  @pattern ||= []
  @pattern.concat(pattern)
end

.inherited(klass) ⇒ Object


44
45
46
# File 'lib/i18nliner/processors/abstract_processor.rb', line 44

def self.inherited(klass)
  Processors.register klass
end

Instance Method Details

#check_file(file) ⇒ Object


39
40
41
42
# File 'lib/i18nliner/processors/abstract_processor.rb', line 39

def check_file(file)
  @file_count += 1
  check_contents(source_for(file), scope_for(file))
end

#check_filesObject


31
32
33
34
35
36
37
# File 'lib/i18nliner/processors/abstract_processor.rb', line 31

def check_files
  Dir.chdir(I18nliner.base_path) do
    files.each do |file|
      @checker.call file, &method(:check_file)
    end
  end
end

#filesObject


23
24
25
26
27
28
29
# File 'lib/i18nliner/processors/abstract_processor.rb', line 23

def files
  @files ||= begin
    files = Globby.select(Array(@pattern))
    files = files.select(Array(@only.dup)) if @only
    files.reject(I18nliner.ignore)
  end
end

#noop_checker(file) {|file| ... } ⇒ Object

Yields:

  • (file)

19
20
21
# File 'lib/i18nliner/processors/abstract_processor.rb', line 19

def noop_checker(file)
  yield file
end