Class: Mo::Runner

Inherits:
Boson::Runner
  • Object
show all
Defined in:
lib/mo.rb

Constant Summary collapse

RUBY_FILES =
%w[**/*.ru **/*.rake Gemfile **/*.rb]
SPEC_FILES =
%w[spec/**/*.rb]
JS_FILES =
%w[**/*.js **/*.coffee]
TPL_FILES =
%w[**/*.haml **/*.erb **/*.slim **/*.jade]
DOC_FILES =
%w[**/*.md **/*.txt **/*.textile]
ALL_FILES =
RUBY_FILES + JS_FILES + DOC_FILES + TPL_FILES

Instance Method Summary collapse

Instance Method Details

#check_rspec_files_name(listener = Kernel) ⇒ Object



73
74
75
76
77
78
79
80
# File 'lib/mo.rb', line 73

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_syntaxObject



63
64
65
66
67
68
69
70
# 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

#eighty_columnObject



29
30
31
32
33
34
35
36
37
# 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) ⇒ Object



53
54
55
56
57
58
59
60
# 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

#rocketlessObject



40
41
42
43
44
45
46
47
48
49
# 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

#whitespaceObject



14
15
16
17
18
19
20
21
22
23
24
25
26
# 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