licit 0.0.1 → 0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,7 +3,7 @@ require 'erb'
3
3
  class Licit::Licenser
4
4
 
5
5
  def initialize(options = {})
6
- defaults = { dir: '.', license: 'GPLv3' }
6
+ defaults = { dir: '.', license: 'GPLv3', exclude: [] }
7
7
  @options = defaults.merge options
8
8
  end
9
9
 
@@ -38,33 +38,38 @@ class Licit::Licenser
38
38
 
39
39
  def check_headers
40
40
  result = []
41
- Dir.chdir(dir) do
42
- Dir['**/*.rb'].each do |source_file|
43
- if not check_file_header(source_file)
44
- result << [:error, source_file, "Missing header in #{source_file}"]
45
- end
41
+ each_source_file do |source_file|
42
+ if not check_file_header(source_file)
43
+ result << [:error, source_file, "Missing header in #{source_file}"]
46
44
  end
47
45
  end
48
46
  result
49
47
  end
50
48
 
51
49
  def fix_headers
52
- Dir.chdir(dir) do
53
- Dir['**/*.rb'].each do |source_file|
54
- if not check_file_header(source_file)
55
- source = File.read source_file
56
- File.open source_file, 'w' do |f|
57
- header.each_line do |header_line|
58
- f.write "# #{header_line}"
59
- end
60
- f.write "\n"
61
- f.write source
50
+ each_source_file do |source_file|
51
+ if not check_file_header(source_file)
52
+ source = File.read source_file
53
+ File.open source_file, 'w' do |f|
54
+ header.each_line do |header_line|
55
+ f.write "# #{header_line}"
62
56
  end
57
+ f.write "\n"
58
+ f.write source
63
59
  end
64
60
  end
65
61
  end
66
62
  end
67
63
 
64
+ def each_source_file
65
+ Dir.chdir(dir) do
66
+ Dir['**/*.rb'].each do |source_file|
67
+ next if should_exclude source_file
68
+ yield source_file
69
+ end
70
+ end
71
+ end
72
+
68
73
  def check_file_header(file)
69
74
  File.open(file, 'r') do |f|
70
75
  begin
@@ -99,9 +104,18 @@ class Licit::Licenser
99
104
  File.join files_dir, file
100
105
  end
101
106
 
107
+ def should_exclude(file)
108
+ @options[:exclude].each do |excluded|
109
+ return true if file.start_with? excluded
110
+ end
111
+ false
112
+ end
113
+
102
114
  def header
103
- template = ERB.new File.read(File.join(license_dir, 'header.erb'))
104
- template.result binding
115
+ @header ||= begin
116
+ template = ERB.new File.read(File.join(license_dir, 'header.erb'))
117
+ template.result binding
118
+ end
105
119
  end
106
120
 
107
121
  def copyright
data/lib/licit/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Licit
2
- VERSION = "0.0.1"
2
+ VERSION = "0.1"
3
3
  end
@@ -40,6 +40,10 @@ along with FooBar. If not, see <http://www.gnu.org/licenses/>.
40
40
  END
41
41
  end
42
42
 
43
+ it "caches header" do
44
+ subject.header.should be(subject.header)
45
+ end
46
+
43
47
  context "dir1" do
44
48
  let(:licenser) { Licit::Licenser.new dir: File.expand_path('../dir1', __FILE__) }
45
49
  after(:each) { FileUtils.rm_f Dir.glob(File.join(File.expand_path('../dir1', __FILE__), '*')) }
@@ -63,6 +67,11 @@ END
63
67
  licenser.check_headers.should =~ [[:error, 'test.rb', 'Missing header in test.rb'], [:error, 'subdir/test1.rb', 'Missing header in subdir/test1.rb']]
64
68
  end
65
69
 
70
+ it "check headers excluding directory" do
71
+ licenser = Licit::Licenser.new dir: File.expand_path('../dir2.tmp', __FILE__), copyright: 'Copyright Line', program_name: 'FooBar', exclude: ['subdir/']
72
+ licenser.check_headers.should =~ [[:error, 'test.rb', 'Missing header in test.rb']]
73
+ end
74
+
66
75
  it "fixes headers" do
67
76
  file = File.expand_path '../dir2.tmp/subdir/test1.rb', __FILE__
68
77
  last_line_before = File.readlines(file).last
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.0.1
4
+ version: '0.1'
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-05-31 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &70354924471140 !ruby/object:Gem::Requirement
16
+ requirement: &70171008169820 !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: *70354924471140
24
+ version_requirements: *70171008169820
25
25
  description: Apply public licenses to files in ruby projects
26
26
  email:
27
27
  - jwajnerman@manas.com.ar