checker 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README +4 -0
- data/bin/checker +4 -0
- data/checker.gemspec +13 -0
- data/lib/checker.rb +7 -0
- data/lib/checker/cli.rb +11 -0
- data/lib/checker/cli/execute.rb +61 -0
- data/lib/checker/core_ext.rb +31 -0
- data/lib/checker/modules/all.rb +16 -0
- data/lib/checker/modules/haml.rb +23 -0
- data/lib/checker/modules/ruby.rb +27 -0
- data/lib/checker/utils.rb +48 -0
- metadata +57 -0
data/README
ADDED
data/bin/checker
ADDED
data/checker.gemspec
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = 'checker'
|
3
|
+
s.version = '0.0.1'
|
4
|
+
s.date = '2012-04-03'
|
5
|
+
s.summary = "Syntax checker for various files"
|
6
|
+
s.description = "A collection of modules which every is designed to check syntax for specific files."
|
7
|
+
s.authors = ["Jacek Jakubik"]
|
8
|
+
s.email = 'jacek.jakubik@netguru.pl'
|
9
|
+
s.files = `git ls-files`.split("\n")
|
10
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
11
|
+
s.require_paths = ["lib"]
|
12
|
+
s.homepage = 'http://github.com/netguru/checker'
|
13
|
+
end
|
data/lib/checker.rb
ADDED
data/lib/checker/cli.rb
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
class CoreExt
|
2
|
+
def self.constantize(camel_cased_word)
|
3
|
+
names = camel_cased_word.split('::')
|
4
|
+
names.shift if names.empty? || names.first.empty?
|
5
|
+
|
6
|
+
constant = Object
|
7
|
+
names.each do |name|
|
8
|
+
constant = constant.const_defined?(name) ? constant.const_get(name) : constant.const_missing(name)
|
9
|
+
end
|
10
|
+
constant
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
class String
|
15
|
+
def constantize
|
16
|
+
CoreExt.constantize(self)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
module Checker
|
21
|
+
class CLI
|
22
|
+
module Execute
|
23
|
+
def self.included(base)
|
24
|
+
base.extend(ClassMethods)
|
25
|
+
end
|
26
|
+
|
27
|
+
module ClassMethods
|
28
|
+
def execute
|
29
|
+
if ARGV.size == 0
|
30
|
+
modules = Utils.get_modules_to_check
|
31
|
+
else
|
32
|
+
modules = ARGV.map(&:downcase)
|
33
|
+
end
|
34
|
+
## by default lets check all
|
35
|
+
if modules.empty?
|
36
|
+
modules = ["all"]
|
37
|
+
end
|
38
|
+
|
39
|
+
## check all the modules
|
40
|
+
if modules.include?("all")
|
41
|
+
exit (Checker::Modules::All.check ? 0 : 1)
|
42
|
+
else
|
43
|
+
Utils.check_module_availability(modules) do |result|
|
44
|
+
puts "Modules not available: #{result.join(", ")}.\n"
|
45
|
+
puts "Available: #{Utils.available_modules.join(", ")}\n"
|
46
|
+
puts "Check your git config checker.check\n"
|
47
|
+
exit 1
|
48
|
+
end
|
49
|
+
|
50
|
+
checked = []
|
51
|
+
modules.each do |mod|
|
52
|
+
klass = "Checker::Modules::#{mod.downcase.capitalize}".constantize
|
53
|
+
checked << klass.check
|
54
|
+
end
|
55
|
+
exit (checked.all_true? ? 0 : 1)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'checker/utils'
|
2
|
+
|
3
|
+
class CoreExt
|
4
|
+
def self.constantize(camel_cased_word)
|
5
|
+
names = camel_cased_word.split('::')
|
6
|
+
names.shift if names.empty? || names.first.empty?
|
7
|
+
|
8
|
+
constant = Object
|
9
|
+
names.each do |name|
|
10
|
+
constant = constant.const_defined?(name) ? constant.const_get(name) : constant.const_missing(name)
|
11
|
+
end
|
12
|
+
constant
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
class String
|
17
|
+
def constantize
|
18
|
+
CoreExt.constantize(self)
|
19
|
+
end
|
20
|
+
|
21
|
+
def ends_with?(patt)
|
22
|
+
patt = Regexp.new(Regexp.escape(patt) + "$")
|
23
|
+
self.match patt
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
class Array
|
28
|
+
def all_true?
|
29
|
+
self.all? {|o| o == true}
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Checker
|
2
|
+
module Modules
|
3
|
+
## simple wrapper, to call every module
|
4
|
+
class All
|
5
|
+
def self.check
|
6
|
+
checked = []
|
7
|
+
constants = Utils.available_modules - ["all"]
|
8
|
+
constants.each do |const|
|
9
|
+
klass = "Checker::Modules::#{const.capitalize}".constantize
|
10
|
+
checked << klass.check
|
11
|
+
end
|
12
|
+
checked.all_true?
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Checker
|
2
|
+
module Modules
|
3
|
+
class Haml
|
4
|
+
def self.check
|
5
|
+
puts ">> HAML <<"
|
6
|
+
|
7
|
+
files = Utils.files_modified
|
8
|
+
files.delete_if {|f| !f.ends_with?(".haml")}
|
9
|
+
|
10
|
+
files.map! do |f|
|
11
|
+
puts "Checking #{f}..."
|
12
|
+
Haml.check_one(f)
|
13
|
+
end
|
14
|
+
|
15
|
+
files.all_true?
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.check_one(file)
|
19
|
+
system("haml --check #{file}")
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Checker
|
2
|
+
module Modules
|
3
|
+
class Ruby
|
4
|
+
def self.check
|
5
|
+
puts ">> RUBY <<"
|
6
|
+
|
7
|
+
files = Utils.files_modified
|
8
|
+
files.delete_if {|f| !f.ends_with?(".rb")}
|
9
|
+
|
10
|
+
files.map! do |f|
|
11
|
+
puts "Checking #{f}..."
|
12
|
+
Ruby.check_one(f)
|
13
|
+
end
|
14
|
+
|
15
|
+
files.all_true?
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.check_one(file)
|
19
|
+
if Utils.use_rvm?
|
20
|
+
Utils.rvm_command("ruby -c #{file}")
|
21
|
+
else
|
22
|
+
Utils.command("ruby -c #{file}")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
class Utils
|
2
|
+
def self.files_modified
|
3
|
+
`git status --porcelain | egrep "^(A |M |R ).*" | awk ' { if ($3 == "->") print $4; else print $2 } '`.split
|
4
|
+
end
|
5
|
+
|
6
|
+
def self.use_rvm?
|
7
|
+
File.exists?(".rvmrc")
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.rvm_command(command)
|
11
|
+
f = File.read(".rvmrc").split("\n").first
|
12
|
+
rvm_version = nil
|
13
|
+
if f.match(/rvm( use|) ([^ ]+)$/)
|
14
|
+
rvm_version = $2
|
15
|
+
end
|
16
|
+
if rvm_version.nil?
|
17
|
+
puts "Cannot determine rvm version"
|
18
|
+
exit 1
|
19
|
+
else
|
20
|
+
puts "Using '#{rvm_version}' version"
|
21
|
+
end
|
22
|
+
cmd = "$rvm_path/bin/rvm-shell '#{rvm_version}' -c '#{command}'"
|
23
|
+
Utils.command cmd
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.command(cmd)
|
27
|
+
system('echo ' + cmd)
|
28
|
+
system(cmd)
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.available_modules
|
32
|
+
Checker::Modules.constants.map(&:to_s).map(&:downcase)
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.check_module_availability(modules)
|
36
|
+
constants = self.available_modules
|
37
|
+
result = modules - (constants & modules)
|
38
|
+
unless result.empty?
|
39
|
+
if block_given?
|
40
|
+
yield(result)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.get_modules_to_check
|
46
|
+
`git config checker.check`.chomp.split(",").map(&:strip)
|
47
|
+
end
|
48
|
+
end
|
metadata
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: checker
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Jacek Jakubik
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-04-03 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: A collection of modules which every is designed to check syntax for specific
|
15
|
+
files.
|
16
|
+
email: jacek.jakubik@netguru.pl
|
17
|
+
executables:
|
18
|
+
- checker
|
19
|
+
extensions: []
|
20
|
+
extra_rdoc_files: []
|
21
|
+
files:
|
22
|
+
- README
|
23
|
+
- bin/checker
|
24
|
+
- checker.gemspec
|
25
|
+
- lib/checker.rb
|
26
|
+
- lib/checker/cli.rb
|
27
|
+
- lib/checker/cli/execute.rb
|
28
|
+
- lib/checker/core_ext.rb
|
29
|
+
- lib/checker/modules/all.rb
|
30
|
+
- lib/checker/modules/haml.rb
|
31
|
+
- lib/checker/modules/ruby.rb
|
32
|
+
- lib/checker/utils.rb
|
33
|
+
homepage: http://github.com/netguru/checker
|
34
|
+
licenses: []
|
35
|
+
post_install_message:
|
36
|
+
rdoc_options: []
|
37
|
+
require_paths:
|
38
|
+
- lib
|
39
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ! '>='
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: '0'
|
45
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
46
|
+
none: false
|
47
|
+
requirements:
|
48
|
+
- - ! '>='
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: '0'
|
51
|
+
requirements: []
|
52
|
+
rubyforge_project:
|
53
|
+
rubygems_version: 1.8.10
|
54
|
+
signing_key:
|
55
|
+
specification_version: 3
|
56
|
+
summary: Syntax checker for various files
|
57
|
+
test_files: []
|