bgem 0.0.12 → 0.0.13

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 +119 -58
  3. metadata +10 -10
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1d1c08e11ff9c3de03b3930c47c20205e61cd0364db2eb246afafa596c36b815
4
- data.tar.gz: 73103ebeb0f449b11a079601a61c02c91285706c95db4d36191abe03bed568c0
3
+ metadata.gz: 9dd5cdb3ff9091a51601230896ac2ea854d3844c422000ce223b83d69e98d7bc
4
+ data.tar.gz: fb6ba38b8f63bb1c0537bee6769654772dc33545744c2507ee14ff0b8ec56aa7
5
5
  SHA512:
6
- metadata.gz: 2bcfe3b46efc42ee2b035459c629647d07ecc51bb88a5280e84a0cac234fcce6e0333b1d7093aa89ea40471183698772a195712007db02c45678f423db2108e8
7
- data.tar.gz: ddb3eef3954990c53eda84f50d60b4d22cf0ffcc63b86dab5f4240af39aa74e3c6804baa1d08f43e28e914dfb4047d063bf24e33d95c7d40e93494dadd1122ec
6
+ metadata.gz: 9dac7f98b123fd0f0c13bd4d271672471feada32915cd6a819bb688147f75b358cda34a0e10a2ef7f25fc93d2501e1768ab7a82a288d523b233d21640a2b3e5b
7
+ data.tar.gz: 31c9c88df1d4eba032cf5945873c11ced2edbbad73ca0b54556e1add0ca479e36bec4fc10f376698b3a9d685f0cc3863f1ad3b3d9cc19738b40fa4082713bad1
data/lib/bgem.rb CHANGED
@@ -9,24 +9,24 @@ module Bgem
9
9
  class << self
10
10
  def run config_file = CONFIG_FILE
11
11
  config = Config.new config_file
12
- target = TargetFile.new config.output, config.scope
13
- target.write SourceFile.new(config.entry).to_s
14
- target
12
+ write = Write.new config
13
+ write[Output.new(config.entry).to_s]
14
+ write
15
15
  end
16
16
  end
17
17
 
18
18
  class Config
19
19
  def initialize config_file
20
20
  @entry, @output, @scope = SOURCE_FILE, 'output.rb', nil
21
- DSL.new self, config_file
21
+ DSL.new self, (IO.read config_file)
22
22
  end
23
23
 
24
24
  attr_accessor :entry, :output, :scope
25
25
 
26
26
  class DSL
27
- def initialize config, file
27
+ def initialize config, code
28
28
  @config = config
29
- instance_eval IO.read file
29
+ instance_eval code
30
30
  end
31
31
 
32
32
  def entry file
@@ -43,67 +43,132 @@ module Bgem
43
43
  end
44
44
  end
45
45
 
46
- class SourceFile
47
- def initialize file = SOURCE_FILE, indent: 0
48
- @file, @indent = (Pathname file), indent
49
- @source = @file.read
50
- head, @type, _rb = @file.basename.to_s.split '.'
51
- @constant, _colon, @ancestor = head.partition ':'
52
- end
53
-
54
- def to_s
55
- "#{head}#{source}end".indent @indent
56
- end
57
-
58
- private
59
- def head
60
- if @ancestor.empty?
61
- "#{@type} #{@constant}\n"
62
- else
63
- "#{@type} #{@constant} < #{@ancestor}\n"
46
+ class Output
47
+ class Ext
48
+ module StandardHooks
49
+ def pre
50
+ pattern = @dir.join "#{__method__}.#{@name}/*.rb"
51
+ concatenate pattern
52
+ end
53
+
54
+ def post
55
+ patterns = ["#{@name}/*.rb", "post.#{@name}/*.rb"].map do |pattern|
56
+ @dir.join pattern
57
+ end
58
+
59
+ concatenate *patterns
60
+ end
61
+
62
+ def concatenate *patterns
63
+ Dir[*patterns].sort.map do |file|
64
+ Output.new(file, indent: INDENT).to_s
65
+ end.join "\n\n"
64
66
  end
65
67
  end
66
68
 
67
- def source
68
- source = @source.indent INDENT
69
- source.prepend "#{pre}\n\n" unless pre.empty?
70
- source.prepend "#{before}\n\n" unless before.empty?
71
- source.concat "\n#{after}\n" unless after.empty?
72
- source
73
- end
74
69
 
75
- def self.define_appendix name
76
- define_method name do
77
- pattern = @file.dirname.join "#{__method__}.#{@constant}/*.rb"
78
- concatenate pattern
70
+ module RB
71
+ def self.new dir:, source:, chain:
72
+ unless chain.size == 2
73
+ fail "#{chain}' size should be 2"
74
+ end
75
+
76
+ name, type = chain
77
+ constant = type.capitalize
78
+
79
+ if self.const_defined? constant
80
+ type = self.const_get constant
81
+ else
82
+ fail "Don't know what to do with '#{type}'. #{self}::#{constant} is not defined."
83
+ end
84
+
85
+ type.new dir: dir, source: source, name: name
86
+ end
87
+
88
+ def initialize dir:, source:, name:
89
+ @dir, @source, @name = dir, source, name
90
+ setup
91
+ end
92
+
93
+ def to_s
94
+ "#{head}#{source}end"
95
+ end
96
+
97
+ private
98
+ def setup
99
+ end
100
+
101
+ include StandardHooks
102
+
103
+ def source
104
+ source = @source.indent INDENT
105
+ source.prepend "#{pre}\n\n" unless pre.empty?
106
+ source.concat "\n#{post}\n" unless post.empty?
107
+ source
108
+ end
109
+
110
+ class Class
111
+ include RB
112
+
113
+ def setup
114
+ @name, _colon, @parent = @name.partition ':'
115
+ end
116
+
117
+ def head
118
+ if subclass?
119
+ "class #{@name} < #{@parent}\n"
120
+ else
121
+ "class #{@name}\n"
122
+ end
123
+ end
124
+
125
+ def subclass?
126
+ not @parent.empty?
127
+ end
128
+ end
129
+
130
+ class Module
131
+ include RB
132
+
133
+ def head
134
+ "module #{@name}\n"
135
+ end
79
136
  end
80
137
  end
138
+ end
139
+
140
+ def initialize file = SOURCE_FILE, indent: 0
141
+ file, @indent = (Pathname file), indent
81
142
 
82
- [:pre, :before].each { |name| define_appendix name }
83
-
84
- def after
85
- patterns = ["#{@constant}/*.rb", "after.#{@constant}/*.rb"].map do |pattern|
86
- @file.dirname.join pattern
87
- end
143
+ *chain, last = file.basename.to_s.split '.'
144
+ name = last.upcase
145
+ source = file.read
146
+ dir = file.dirname
88
147
 
89
- concatenate *patterns
148
+ if Ext.const_defined? name
149
+ ext = Ext.const_get name
150
+ else
151
+ fail "Don't know what to do with #{file}. Bgem::Output::Ext::#{name} is not defined."
90
152
  end
91
153
 
92
- def concatenate *patterns
93
- Dir[*patterns].sort.map do |file|
94
- self.class.new(file, indent: INDENT).to_s
95
- end.join "\n\n"
96
- end
154
+ @output = ext.new dir: dir, source: source, chain: chain
155
+ end
156
+
157
+ def to_s
158
+ @output.to_s.indent @indent
159
+ end
97
160
  end
98
161
 
99
- class TargetFile
100
- def initialize path = 'output.rb', scope
101
- @path = Pathname path
102
- @scope = scope
162
+ class Write
163
+ def initialize config
164
+ @file = Pathname config.output
165
+ @scope = config.scope
103
166
  end
104
167
 
105
- def write string
106
- @path.dirname.mkpath
168
+ attr_reader :file
169
+
170
+ def [] string
171
+ file.dirname.mkpath
107
172
 
108
173
  if @scope
109
174
  @scope.each do |header|
@@ -111,11 +176,7 @@ module Bgem
111
176
  end
112
177
  end
113
178
 
114
- @path.write "#{string}\n"
115
- end
116
-
117
- def file
118
- @path
179
+ file.write "#{string}\n"
119
180
  end
120
181
  end
121
182
  end
metadata CHANGED
@@ -1,27 +1,27 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bgem
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.12
4
+ version: 0.0.13
5
5
  platform: ruby
6
6
  authors:
7
- - Anatoly Chernow
7
+ - Anatoly Chernov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-04-25 00:00:00.000000000 Z
11
+ date: 2021-04-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: string-indent
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: 0.0.1
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: 0.0.1
27
27
  description:
@@ -33,8 +33,9 @@ extra_rdoc_files: []
33
33
  files:
34
34
  - bin/bgem
35
35
  - lib/bgem.rb
36
- homepage:
37
- licenses: []
36
+ homepage: https://github.com/ch1c0t/bgem
37
+ licenses:
38
+ - ISC
38
39
  metadata: {}
39
40
  post_install_message:
40
41
  rdoc_options: []
@@ -51,9 +52,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
51
52
  - !ruby/object:Gem::Version
52
53
  version: '0'
53
54
  requirements: []
54
- rubyforge_project:
55
- rubygems_version: 2.7.6
55
+ rubygems_version: 3.1.6
56
56
  signing_key:
57
57
  specification_version: 4
58
- summary: Build gems without too much hassle.
58
+ summary: A tool to build single-file Ruby gems with less ends.
59
59
  test_files: []