bgem 0.0.5 → 0.0.6
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 +58 -11
- 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: 84b22f474c71f377fc405b697c569581246aa48d
|
4
|
+
data.tar.gz: a6949a75c4d620687b8612fc30c0972cab7f2409
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 97bfbcea8b2e30a531ea8c2530cda1e523f5e10a93b7bb455c9adcb663bd8e08138a3cf5db6610f329f15ba95a6260832810dd4d80ad6f792a9f20c77aeb0e36
|
7
|
+
data.tar.gz: 07d1e106020e812fb4becff059c71d24e38c2f147aca9fd0360a9425b1b258adc0cd0b1bddfeeb5bf5611bd6cbba0b814b490995d831542447d89661c06d87cb
|
data/lib/bgem.rb
CHANGED
@@ -11,6 +11,16 @@ module Bgem
|
|
11
11
|
|
12
12
|
INDENT = 2
|
13
13
|
SOURCE_FILE = Dir['src/*.rb'][0]
|
14
|
+
CONFIG_FILE = "#{Dir.pwd}/bgem/config.rb"
|
15
|
+
|
16
|
+
class << self
|
17
|
+
def run config_file
|
18
|
+
config = Config.new (config_file or CONFIG_FILE)
|
19
|
+
target = TargetFile.new config.output, config.scope.reverse
|
20
|
+
target.write SourceFile.new(config.entry).to_s
|
21
|
+
target
|
22
|
+
end
|
23
|
+
end
|
14
24
|
|
15
25
|
module CLI
|
16
26
|
def self.run
|
@@ -27,22 +37,31 @@ module Bgem
|
|
27
37
|
end
|
28
38
|
end
|
29
39
|
|
30
|
-
class
|
31
|
-
def initialize
|
32
|
-
@
|
33
|
-
|
40
|
+
class Config
|
41
|
+
def initialize config_file
|
42
|
+
@entry, @output, @scope = SOURCE_FILE, 'output.rb', nil
|
43
|
+
DSL.new self, config_file
|
34
44
|
end
|
35
45
|
|
36
|
-
|
37
|
-
@path.dirname.mkpath
|
46
|
+
attr_accessor :entry, :output, :scope
|
38
47
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
48
|
+
class DSL
|
49
|
+
def initialize config, file
|
50
|
+
@config = config
|
51
|
+
instance_eval IO.read file
|
52
|
+
end
|
53
|
+
|
54
|
+
def entry file
|
55
|
+
@config.entry = file
|
43
56
|
end
|
44
57
|
|
45
|
-
|
58
|
+
def output file
|
59
|
+
@config.output = file
|
60
|
+
end
|
61
|
+
|
62
|
+
def inside *array_of_strings
|
63
|
+
@config.scope = array_of_strings
|
64
|
+
end
|
46
65
|
end
|
47
66
|
end
|
48
67
|
|
@@ -87,4 +106,32 @@ module Bgem
|
|
87
106
|
|
88
107
|
concatenate_source_files :before, :after
|
89
108
|
end
|
109
|
+
|
110
|
+
class TargetFile
|
111
|
+
def initialize path = 'output.rb', scope = nil
|
112
|
+
@path = Pathname path
|
113
|
+
@scope = case scope
|
114
|
+
when Array
|
115
|
+
scope
|
116
|
+
when String
|
117
|
+
eval scope
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
def write string
|
122
|
+
@path.dirname.mkpath
|
123
|
+
|
124
|
+
if @scope
|
125
|
+
@scope.reverse_each do |head_of_constant_definition|
|
126
|
+
string = "#{head_of_constant_definition}\n#{string.indent INDENT}\nend"
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
@path.write "#{string}\n"
|
131
|
+
end
|
132
|
+
|
133
|
+
def file
|
134
|
+
@path
|
135
|
+
end
|
136
|
+
end
|
90
137
|
end
|