class Mo::Runner
Constants
- ALL_FILES
- DOC_FILES
- JS_FILES
- RUBY_FILES
- SPEC_FILES
- TPL_FILES
Public Instance Methods
check_rspec_files_name(listener = Kernel)
click to toggle source
# File lib/mo.rb, line 86 def check_rspec_files_name(listener = Kernel) ignores_dirs = %w[spec/factories spec/mocks spec/support spec/fabricators spec/fixtures spec/spec_helper.rb] Dir[*SPEC_FILES].each do |file| next if file.match(/_spec.rb$/) listener.puts " * #{file}" unless ignores_dirs.any? {|dir| file.include?(dir) } end end
check_syntax()
click to toggle source
# File lib/mo.rb, line 63 def check_syntax Dir[*RUBY_FILES].each do |file| if File.readable? file puts " * #{file}" puts `#{which('ruby')} -wc #{file}`.chomp end end end
check_unbreakable_space(listener = Kernel)
click to toggle source
# File lib/mo.rb, line 73 def check_unbreakable_space(listener = Kernel) Dir[*RUBY_FILES].each do |file| if File.readable? file source = File.open(file).read regexp = /\u00A0/ if source.scan(regexp).any? listener.puts " * #{file}" end end end end
eighty_column()
click to toggle source
# File lib/mo.rb, line 29 def eighty_column Dir[*ALL_FILES].each do |file| output = `grep -n '.\\{80,\\}' #{file}` unless output.empty? puts file puts output end end end
encoding(listener = Kernel)
click to toggle source
# File lib/mo.rb, line 53 def encoding(listener = Kernel) Dir[*RUBY_FILES].each do |file| if `head -n 2 #{file} | grep -E '# encoding\|-\*- coding'`.empty? listener.system "sed -i -r '1 s/^(.*)$/# encoding: utf-8\\n\\1/g' #{file}" puts " * #{file}" end end end
rocketless()
click to toggle source
# File lib/mo.rb, line 40 def rocketless Dir[*RUBY_FILES].each do |file| source = File.open(file).read regexp = /(?<!return)(?<!:)(?<!\w)(\s+):(\w+)\s*=>/ next if source.scan(regexp).any? source.gsub!(regexp, '\1\2:') open(file, 'w') { |b| b << source } puts " * #{file}" end end
whitespace()
click to toggle source
# File lib/mo.rb, line 14 def whitespace Dir[*ALL_FILES].each do |file| next if File.directory?(file) wsps = false File.open(file).each_line do |line| break if wsps = line.match(/( |\t)*$/).captures.compact.any? end if wsps system "sed -e 's/[ \t]*$//' -i #{file}" puts " * #{file}" end end end
Private Instance Methods
which(cmd)
click to toggle source
Cross-platform way of finding an executable in the $PATH. Taken from stackoverflow.com/questions/2108727/which-in-ruby-checking-if-program-exists-in-path-from-ruby
which('ruby') #=> /usr/bin/ruby
# File lib/mo.rb, line 102 def which(cmd) exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : [''] ENV['PATH'].split(File::PATH_SEPARATOR).each do |path| exts.each { |ext| exe = "#{path}/#{cmd}#{ext}" return exe if File.executable? exe } end return nil end