bgem 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/bgem.rb +28 -21
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2ed05b7d214f5a77ec8095c02fafed93a5d0b748
|
4
|
+
data.tar.gz: 19df71a50194389b49c4dd121e2b1e9ffcfe3afa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 03131c1b4ff6f1ecd9e6dc726b3e5c2cda2a3467007ac30d31e40db8619ad7322f6d47d7ddf75653e3b7e66558e657c3266ce7b96ba2dc87ccf26ef3377b4831
|
7
|
+
data.tar.gz: cf4ac4b56db04f9bcd868101ba991b97a6fe3c43ee5b732716acc18abf06bca4865a03b2480a81fb5c913045fba4c1c8d0406f82e1800c504adae37cdfbab162
|
data/lib/bgem.rb
CHANGED
@@ -8,28 +8,12 @@ module Bgem
|
|
8
8
|
end
|
9
9
|
end
|
10
10
|
}
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
def self.run
|
16
|
-
options = parse_argv
|
17
|
-
target = TargetFile.new (options[:output] || 'output.rb')
|
18
|
-
target.write SourceFile.new(options[:input] || MAIN_FILE).to_s
|
19
|
-
end
|
20
|
-
|
21
|
-
def self.parse_argv
|
22
|
-
ARGV.map do |string|
|
23
|
-
key, _colon, value = string.partition ':'
|
24
|
-
[key.to_sym, value]
|
25
|
-
end.to_h
|
26
|
-
end
|
27
|
-
end
|
11
|
+
|
12
|
+
INDENT = 2
|
13
|
+
SOURCE_FILE = Dir['src/*.rb'][0]
|
28
14
|
|
29
15
|
class SourceFile
|
30
|
-
|
31
|
-
|
32
|
-
def initialize file, indent: 0
|
16
|
+
def initialize file = SOURCE_FILE, indent: 0
|
33
17
|
@file, @indent = (Pathname file), indent
|
34
18
|
@source = @file.read
|
35
19
|
@constant, @type, _rb = @file.basename.to_s.split '.'
|
@@ -61,13 +45,36 @@ module Bgem
|
|
61
45
|
concatenate_source_files :before, :after
|
62
46
|
end
|
63
47
|
|
48
|
+
module CLI
|
49
|
+
def self.run
|
50
|
+
options = parse_argv
|
51
|
+
target = TargetFile.new *options[:output], options[:scope]
|
52
|
+
target.write SourceFile.new(*options[:input]).to_s
|
53
|
+
end
|
54
|
+
|
55
|
+
def self.parse_argv
|
56
|
+
ARGV.map do |string|
|
57
|
+
key, _colon, value = string.partition ':'
|
58
|
+
[key.to_sym, value]
|
59
|
+
end.to_h
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
64
63
|
class TargetFile
|
65
|
-
def initialize path
|
64
|
+
def initialize path = 'output.rb', scope = nil
|
66
65
|
@path = Pathname path
|
66
|
+
@scope = eval scope if scope
|
67
67
|
end
|
68
68
|
|
69
69
|
def write string
|
70
70
|
@path.dirname.mkpath
|
71
|
+
|
72
|
+
if @scope
|
73
|
+
@scope.reverse_each do |head_of_constant_definition|
|
74
|
+
string = "#{head_of_constant_definition}\n#{string.indent INDENT}\nend"
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
71
78
|
@path.write string
|
72
79
|
end
|
73
80
|
end
|