prepend_code 0.0.1 → 0.0.2
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.md +9 -11
- data/lib/prepend_code/version.rb +1 -1
- data/lib/prepend_code.rb +28 -12
- metadata +3 -3
data/README.md
CHANGED
@@ -1,13 +1,15 @@
|
|
1
1
|
# prepend_code
|
2
2
|
|
3
3
|
prepend_code will prepend context on your files.
|
4
|
+
coding directive, copy right etc..
|
5
|
+
Because Files that has been generated by scaffold function, does'nt have conding directive.
|
4
6
|
|
5
7
|
prepend_code mainly supports:
|
6
8
|
|
7
9
|
* It handles recursively to the directory.
|
8
10
|
|
9
11
|
## Supported Ruby versions and implementations
|
10
|
-
I've tested on:
|
12
|
+
I've tested on:
|
11
13
|
|
12
14
|
* Ruby 1.9.3
|
13
15
|
|
@@ -18,19 +20,15 @@ I've tested on:(maybe move on 1.8.7, 1.9.2 too)
|
|
18
20
|
## Usage
|
19
21
|
|
20
22
|
### on your rails project directory
|
21
|
-
$ prepend_code
|
23
|
+
$ prepend_code target_director context
|
24
|
+
|
25
|
+
# example
|
26
|
+
$ prepend_code ./app "# coding: utf-8"
|
27
|
+
$ prepend_code ./lib "# Copyright (c) 2013 ryooo321"
|
22
28
|
|
23
29
|
### view all options by --help.
|
24
30
|
$ prepend_code --help
|
25
31
|
|
26
|
-
### specify context.
|
27
|
-
$ prepend_code -t "# Copyright (c) 2013 ryooo321."
|
28
|
-
# default is # coding: utf-8
|
29
|
-
|
30
|
-
### specify target directory.
|
31
|
-
$ prepend_code -d ./lib
|
32
|
-
# default is ./app
|
33
|
-
|
34
32
|
### specify target file extension.
|
35
33
|
$ prepend_code -e .erb
|
36
34
|
# default is .rb
|
@@ -51,7 +49,7 @@ I've tested on:(maybe move on 1.8.7, 1.9.2 too)
|
|
51
49
|
|
52
50
|
### Other
|
53
51
|
|
54
|
-
## Contributing to
|
52
|
+
## Contributing to prepend_code
|
55
53
|
|
56
54
|
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
57
55
|
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
|
data/lib/prepend_code/version.rb
CHANGED
data/lib/prepend_code.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require "prepend_code/version"
|
2
|
+
require "readline"
|
2
3
|
begin
|
3
4
|
require "pry"
|
4
5
|
rescue LoadError
|
@@ -6,25 +7,40 @@ end
|
|
6
7
|
|
7
8
|
module PrependCode
|
8
9
|
module Application
|
10
|
+
def self.exit_with_usage
|
11
|
+
puts @opts.to_s
|
12
|
+
return 0
|
13
|
+
end
|
14
|
+
|
9
15
|
def self.run!(*arguments)
|
10
|
-
dir_base = './app'
|
11
16
|
ext = '.rb'
|
12
|
-
|
13
|
-
opts = OptionParser.new
|
14
|
-
opts.on("-
|
15
|
-
opts.
|
16
|
-
|
17
|
-
|
17
|
+
banner = "Usage: prepend_code target_directory context [options]"
|
18
|
+
@opts = OptionParser.new(banner)
|
19
|
+
@opts.on("-e [extension]", "target file extension. (default: .rb)"){|v| ext = v }
|
20
|
+
@opts.parse!(arguments)
|
21
|
+
dir_base = arguments[0]
|
22
|
+
context = arguments[1]
|
23
|
+
return self.exit_with_usage if context.nil?
|
24
|
+
return self.exit_with_usage if dir_base.nil?
|
18
25
|
|
19
26
|
file_paths = find_file_paths(dir_base, ext)
|
27
|
+
loop do
|
28
|
+
messages = []
|
29
|
+
messages << sprintf("Target directory is %s", dir_base)
|
30
|
+
messages << sprintf("Context is %s", context)
|
31
|
+
messages << sprintf("Target file count is %s. Are yor sure?[Y/n]", file_paths.count)
|
32
|
+
input = Readline.readline(messages.join("\n"))
|
33
|
+
break if input == 'Y'
|
34
|
+
return 0 if input == 'n'
|
35
|
+
end
|
20
36
|
|
21
37
|
count = 0
|
22
38
|
file_paths.each do |file_path|
|
23
|
-
result = prepend_on_file!(file_path,
|
39
|
+
result = prepend_on_file!(file_path, context)
|
24
40
|
count += 1 if result
|
25
41
|
end
|
26
42
|
puts sprintf('%s files has been matched.', file_paths.count)
|
27
|
-
puts sprintf('%s files has been
|
43
|
+
puts sprintf('%s files has been updated.', count)
|
28
44
|
return 1
|
29
45
|
end
|
30
46
|
|
@@ -48,13 +64,13 @@ module PrependCode
|
|
48
64
|
return ret
|
49
65
|
end
|
50
66
|
|
51
|
-
def self.prepend_on_file!(file_path,
|
67
|
+
def self.prepend_on_file!(file_path, context)
|
52
68
|
f = File.open(file_path, "r+")
|
53
69
|
lines = f.readlines
|
54
70
|
f.close
|
55
71
|
|
56
|
-
return false if lines && lines[0] ==
|
57
|
-
lines = [sprintf('%s%s',
|
72
|
+
return false if lines && lines[0] == context + "\n"
|
73
|
+
lines = [sprintf('%s%s', context, "\n")] + lines
|
58
74
|
output = File.new(file_path, "w")
|
59
75
|
lines.each { |line| output.write line }
|
60
76
|
output.close
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: prepend_code
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-02-
|
12
|
+
date: 2013-02-17 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: OptionParser
|
@@ -101,7 +101,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
101
101
|
version: '0'
|
102
102
|
requirements: []
|
103
103
|
rubyforge_project:
|
104
|
-
rubygems_version: 1.8.
|
104
|
+
rubygems_version: 1.8.25
|
105
105
|
signing_key:
|
106
106
|
specification_version: 3
|
107
107
|
summary: Prepend context on all app ruby files.
|