bgem 0.0.5 → 0.0.6

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 +58 -11
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6cbea40c715a865694f8213ef1dd67f7efb4d628
4
- data.tar.gz: cb8ff70ec992c30cdde41d1cf8f38471275395ae
3
+ metadata.gz: 84b22f474c71f377fc405b697c569581246aa48d
4
+ data.tar.gz: a6949a75c4d620687b8612fc30c0972cab7f2409
5
5
  SHA512:
6
- metadata.gz: 9223e7c37b3bd65ab93fd31b23a2e918dd80c3df8f69d28750e3969629db37d276eccb857eb1d8490ee08a2a301c7e4b68e08b7fbee27ef51a24ad8ab4f810e0
7
- data.tar.gz: 3ba09434034de3e40ba2bc1ed0a75fb897819b44c885aa124ace36dfc4851bc2954c84e70289449d016172ad0bb03f8433ca8b51749fe734660b6a6fd2313a0f
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 TargetFile
31
- def initialize path = 'output.rb', scope = nil
32
- @path = Pathname path
33
- @scope = eval scope if scope
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
- def write string
37
- @path.dirname.mkpath
46
+ attr_accessor :entry, :output, :scope
38
47
 
39
- if @scope
40
- @scope.reverse_each do |head_of_constant_definition|
41
- string = "#{head_of_constant_definition}\n#{string.indent INDENT}\nend"
42
- end
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
- @path.write string
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
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.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anatoly Chernow