licit 0.1 → 0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/licit/command.rb +3 -0
- data/lib/licit/licenser.rb +23 -3
- data/lib/licit/version.rb +1 -1
- data/spec/dir2/subdir/test3.rb +21 -0
- metadata +6 -4
data/lib/licit/command.rb
CHANGED
@@ -11,9 +11,12 @@ class Licit::Command
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def check(licenser)
|
14
|
+
has_errors = false
|
14
15
|
(licenser.check_files | licenser.check_headers).each do |severity, file, message|
|
15
16
|
puts message
|
17
|
+
has_errors = true if severity == :error
|
16
18
|
end
|
19
|
+
exit (has_errors ? 1 : 0)
|
17
20
|
end
|
18
21
|
|
19
22
|
def fix(licenser)
|
data/lib/licit/licenser.rb
CHANGED
@@ -49,13 +49,21 @@ class Licit::Licenser
|
|
49
49
|
def fix_headers
|
50
50
|
each_source_file do |source_file|
|
51
51
|
if not check_file_header(source_file)
|
52
|
-
|
52
|
+
source_lines = File.readlines source_file
|
53
|
+
|
54
|
+
|
55
|
+
|
53
56
|
File.open source_file, 'w' do |f|
|
57
|
+
while should_skip? source_lines.first
|
58
|
+
f.write source_lines.shift
|
59
|
+
end
|
54
60
|
header.each_line do |header_line|
|
55
61
|
f.write "# #{header_line}"
|
56
62
|
end
|
57
63
|
f.write "\n"
|
58
|
-
|
64
|
+
source_lines.each do |line|
|
65
|
+
f.write line
|
66
|
+
end
|
59
67
|
end
|
60
68
|
end
|
61
69
|
end
|
@@ -71,10 +79,15 @@ class Licit::Licenser
|
|
71
79
|
end
|
72
80
|
|
73
81
|
def check_file_header(file)
|
82
|
+
at_beginning = true
|
74
83
|
File.open(file, 'r') do |f|
|
75
84
|
begin
|
76
85
|
header.each_line do |header_line|
|
77
|
-
|
86
|
+
begin
|
87
|
+
file_line = f.readline
|
88
|
+
end while at_beginning && should_skip?(file_line)
|
89
|
+
at_beginning = false
|
90
|
+
|
78
91
|
return false unless file_line.start_with? '#'
|
79
92
|
file_line = file_line[1..-1].strip
|
80
93
|
return false if file_line != header_line.chomp
|
@@ -86,6 +99,13 @@ class Licit::Licenser
|
|
86
99
|
true
|
87
100
|
end
|
88
101
|
|
102
|
+
def should_skip? line
|
103
|
+
line = line.strip
|
104
|
+
return true if line.empty?
|
105
|
+
return true if line.start_with? '#!'
|
106
|
+
return line =~ /^#\s*(encoding|coding)/
|
107
|
+
end
|
108
|
+
|
89
109
|
def files
|
90
110
|
Dir.chdir(files_dir) do
|
91
111
|
return Dir['**']
|
data/lib/licit/version.rb
CHANGED
@@ -0,0 +1,21 @@
|
|
1
|
+
#!/bin/env ruby
|
2
|
+
#encoding: utf8
|
3
|
+
|
4
|
+
# Copyright Line
|
5
|
+
#
|
6
|
+
# This file is part of FooBar.
|
7
|
+
#
|
8
|
+
# FooBar is free software: you can redistribute it and/or modify
|
9
|
+
# it under the terms of the GNU General Public License as published by
|
10
|
+
# the Free Software Foundation, either version 3 of the License, or
|
11
|
+
# (at your option) any later version.
|
12
|
+
#
|
13
|
+
# FooBar is distributed in the hope that it will be useful,
|
14
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16
|
+
# GNU General Public License for more details.
|
17
|
+
#
|
18
|
+
# You should have received a copy of the GNU General Public License
|
19
|
+
# along with FooBar. If not, see <http://www.gnu.org/licenses/>.
|
20
|
+
|
21
|
+
puts "Hello world"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: licit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.2'
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-06-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
requirement: &
|
16
|
+
requirement: &70251677218640 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,7 +21,7 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70251677218640
|
25
25
|
description: Apply public licenses to files in ruby projects
|
26
26
|
email:
|
27
27
|
- jwajnerman@manas.com.ar
|
@@ -45,6 +45,7 @@ files:
|
|
45
45
|
- spec/command_spec.rb
|
46
46
|
- spec/dir2/subdir/test1.rb
|
47
47
|
- spec/dir2/subdir/test2.rb
|
48
|
+
- spec/dir2/subdir/test3.rb
|
48
49
|
- spec/dir2/test.rb
|
49
50
|
- spec/dir3/licit.yml
|
50
51
|
- spec/licenser_spec.rb
|
@@ -80,6 +81,7 @@ test_files:
|
|
80
81
|
- spec/command_spec.rb
|
81
82
|
- spec/dir2/subdir/test1.rb
|
82
83
|
- spec/dir2/subdir/test2.rb
|
84
|
+
- spec/dir2/subdir/test3.rb
|
83
85
|
- spec/dir2/test.rb
|
84
86
|
- spec/dir3/licit.yml
|
85
87
|
- spec/licenser_spec.rb
|