bgem 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/bgem.rb +28 -21
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: eac187349299661854ca19def82c05e8abb8100a
4
- data.tar.gz: 9d227807b5776bba0a66d7a58c20a80bb201055b
3
+ metadata.gz: 2ed05b7d214f5a77ec8095c02fafed93a5d0b748
4
+ data.tar.gz: 19df71a50194389b49c4dd121e2b1e9ffcfe3afa
5
5
  SHA512:
6
- metadata.gz: 1b9b60f6c13811f3c3c4a9082d694d9003ece5140a16638bb6f3e3629e13580337f7d45ff8851b323b46663fc5d146c2e3a8e1bcf3a1106d4c573644af236d7b
7
- data.tar.gz: 0de32c5845c033abb8e0d8347674d8c11222ccb4cb9d69eb8587fb1f5d80efd63cb91f590a96aa407ba7e1d9c420ff796ee2b4487d8d566907725702dd9a687f
6
+ metadata.gz: 03131c1b4ff6f1ecd9e6dc726b3e5c2cda2a3467007ac30d31e40db8619ad7322f6d47d7ddf75653e3b7e66558e657c3266ce7b96ba2dc87ccf26ef3377b4831
7
+ data.tar.gz: cf4ac4b56db04f9bcd868101ba991b97a6fe3c43ee5b732716acc18abf06bca4865a03b2480a81fb5c913045fba4c1c8d0406f82e1800c504adae37cdfbab162
@@ -8,28 +8,12 @@ module Bgem
8
8
  end
9
9
  end
10
10
  }
11
-
12
- module CLI
13
- MAIN_FILE = Dir['src/*.rb'][0]
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
- INDENT = 2
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bgem
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anatoly Chernow