Class: Guard::Ragel
Constant Summary collapse
- RagelError =
Class.new(RuntimeError)
- EXTENSIONS =
{ :c => 'c', :d => 'd', :go => 'go', :java => 'java', :ruby => 'rb', :csharp => 'cs', :ocaml => 'caml', }
- FORMAT_FLAGS =
{ 'c' => '-C', 'd' => '-D', 'go' => '-Z', 'java' => '-J', 'rb' => '-R', 'cs' => '-A', 'caml' => '-O' }
- DEFAULTS =
{ :output_format => :ruby, # Output format to use if it cannot be # determined from the original filename :options => '', # Options to pass to ragel :notification => true, # Enable notifications? :extension => nil, # Override output extension }
Instance Method Summary collapse
-
#build_ragel(file) ⇒ String
Runs ragel over the input file with specified options.
-
#initialize(watchers = [], options = {}) ⇒ Ragel
constructor
A new instance of Ragel.
- #notify(changed_files) ⇒ Object
-
#run_all ⇒ Object
Build all files being watched.
-
#run_on_change(paths) ⇒ Object
Build the files given.
Constructor Details
Instance Method Details
#build_ragel(file) ⇒ String
Runs ragel over the input file with specified options.
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/guard/ragel.rb', line 46 def build_ragel(file) output_dir = [:output] || File.dir(file) filename, extension = output_filename(file) format_type = [:output_format] extension ||= EXTENSIONS[format_type] if extension.nil? raise ArgumentError, "Unable to determine output format from #{filename} with default output #{format_type}" end format_flag = FORMAT_FLAGS[extension] if override_extension = [:extension] extension = override_extension end output_file = File.join(output_dir, "#{filename}.#{extension}") result = system "ragel #{[:options]} #{format_flag} #{file} -o #{output_file}" raise RagelError, $? unless result output_file end |
#notify(changed_files) ⇒ Object
102 103 104 105 106 107 |
# File 'lib/guard/ragel.rb', line 102 def notify(changed_files) ::Guard.guards.reject{ |guard| guard == self }.each do |guard| paths = Watcher.match_files(guard, changed_files) guard.run_on_change paths unless paths.empty? end end |
#run_all ⇒ Object
Build all files being watched
70 71 72 |
# File 'lib/guard/ragel.rb', line 70 def run_all run_on_change(Watcher.match_files(self, Dir.glob(File.join('**', '*.*')))) end |
#run_on_change(paths) ⇒ Object
Build the files given
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/guard/ragel.rb', line 75 def run_on_change(paths) changed_files = paths.reject{ |f| File.basename(f)[0] == "_" }.map do |file| begin output_file = build_ragel(file) = "generated '#{output_file}' from '#{file}'" ::Guard::UI.info "Guard::Ragel -> #{}", :reset => true if [:notification] ::Guard::Notifier.notify(, :title => "Guard::Ragel", :image => :success) end output_file rescue RagelError => error = "failed to generate '#{output_file}' from '#{file}', error #{error.}" ::Guard::UI.error "Guard::Ragel -> #{}" if [:notification] ::Guard::Notifier.notify(, :title => "Guard::Ragel", :image => :error) end nil end end.compact notify changed_files end |