Class: Haml::I18n::Extractor::Workflow

Inherits:
Object
  • Object
show all
Defined in:
lib/haml-i18n-extractor/workflow.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(project_path, options = {}) ⇒ Workflow

Returns a new instance of Workflow.



8
9
10
11
12
13
14
15
16
# File 'lib/haml-i18n-extractor/workflow.rb', line 8

def initialize(project_path, options = {})
  @extractors = []
  @passed_options = options
  @project_path = project_path
  @prompter = Haml::I18n::Extractor::Prompter.new
  unless File.directory?(@project_path)
    raise Extractor::NotADirectory, "#{@project_path} needs to be a directory!"
  end
end

Instance Attribute Details

#extractorsObject (readonly)

Returns the value of attribute extractors.



6
7
8
# File 'lib/haml-i18n-extractor/workflow.rb', line 6

def extractors
  @extractors
end

Instance Method Details

#filesObject



22
23
24
25
26
# File 'lib/haml-i18n-extractor/workflow.rb', line 22

def files
  @haml_files ||= Dir.glob(@project_path + "/**/*").select do |file|
   file.match /.haml$/
  end
end

#interactive?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/haml-i18n-extractor/workflow.rb', line 18

def interactive?
  !!@passed_options[:interactive]
end

#process_file?(file) ⇒ Boolean

Returns:

  • (Boolean)


34
35
36
37
# File 'lib/haml-i18n-extractor/workflow.rb', line 34

def process_file?(file)
  file_index = index_for(file)
  @prompter.process_file?(file, file_index)
end

#runObject



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/haml-i18n-extractor/workflow.rb', line 39

def run
  if interactive?
    start_message
    files.each do |haml_path|
      type = process_file?(haml_path)
      if type
        process(haml_path, type)
      else
        @prompter.not_processing(haml_path)
      end
    end
    end_message
  else
    files.each do |haml_path|
      process(haml_path, :overwrite)
    end
  end
end

#start_messageObject



28
29
30
31
32
# File 'lib/haml-i18n-extractor/workflow.rb', line 28

def start_message
  file_count = files.size
  file_names = files.join("\n")
  @prompter.start_message(file_count, file_names)
end