bgem 0.0.8 → 0.0.13
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/lib/bgem.rb +126 -81
- metadata +23 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 9dd5cdb3ff9091a51601230896ac2ea854d3844c422000ce223b83d69e98d7bc
|
4
|
+
data.tar.gz: fb6ba38b8f63bb1c0537bee6769654772dc33545744c2507ee14ff0b8ec56aa7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9dac7f98b123fd0f0c13bd4d271672471feada32915cd6a819bb688147f75b358cda34a0e10a2ef7f25fc93d2501e1768ab7a82a288d523b233d21640a2b3e5b
|
7
|
+
data.tar.gz: 31c9c88df1d4eba032cf5945873c11ced2edbbad73ca0b54556e1add0ca479e36bec4fc10f376698b3a9d685f0cc3863f1ad3b3d9cc19738b40fa4082713bad1
|
data/lib/bgem.rb
CHANGED
@@ -1,13 +1,6 @@
|
|
1
1
|
module Bgem
|
2
2
|
require 'pathname'
|
3
|
-
|
4
|
-
using Module.new {
|
5
|
-
refine String do
|
6
|
-
def indent number
|
7
|
-
lines.map { |line| "#{' '*number}#{line}" }.join
|
8
|
-
end
|
9
|
-
end
|
10
|
-
}
|
3
|
+
require 'string/indent'
|
11
4
|
|
12
5
|
INDENT = 2
|
13
6
|
SOURCE_FILE = Dir['src/*.rb'][0]
|
@@ -16,39 +9,24 @@ module Bgem
|
|
16
9
|
class << self
|
17
10
|
def run config_file = CONFIG_FILE
|
18
11
|
config = Config.new config_file
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
module CLI
|
26
|
-
def self.run
|
27
|
-
options = parse_argv
|
28
|
-
target = TargetFile.new *options[:output], options[:scope]
|
29
|
-
target.write SourceFile.new(*options[:input]).to_s
|
30
|
-
end
|
31
|
-
|
32
|
-
def self.parse_argv
|
33
|
-
ARGV.map do |string|
|
34
|
-
key, _colon, value = string.partition ':'
|
35
|
-
[key.to_sym, value]
|
36
|
-
end.to_h
|
12
|
+
write = Write.new config
|
13
|
+
write[Output.new(config.entry).to_s]
|
14
|
+
write
|
37
15
|
end
|
38
16
|
end
|
39
17
|
|
40
18
|
class Config
|
41
19
|
def initialize config_file
|
42
20
|
@entry, @output, @scope = SOURCE_FILE, 'output.rb', nil
|
43
|
-
DSL.new self, config_file
|
21
|
+
DSL.new self, (IO.read config_file)
|
44
22
|
end
|
45
23
|
|
46
24
|
attr_accessor :entry, :output, :scope
|
47
25
|
|
48
26
|
class DSL
|
49
|
-
def initialize config,
|
27
|
+
def initialize config, code
|
50
28
|
@config = config
|
51
|
-
instance_eval
|
29
|
+
instance_eval code
|
52
30
|
end
|
53
31
|
|
54
32
|
def entry file
|
@@ -59,79 +37,146 @@ module Bgem
|
|
59
37
|
@config.output = file
|
60
38
|
end
|
61
39
|
|
62
|
-
def inside *
|
63
|
-
@config.scope =
|
40
|
+
def inside *headers
|
41
|
+
@config.scope = headers
|
64
42
|
end
|
65
43
|
end
|
66
44
|
end
|
67
45
|
|
68
|
-
class
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
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"
|
86
66
|
end
|
87
67
|
end
|
88
68
|
|
89
|
-
def source
|
90
|
-
source = @source.indent INDENT
|
91
|
-
source.prepend "#{before}\n\n" unless before.empty?
|
92
|
-
source.concat "\n#{after}\n" unless after.empty?
|
93
|
-
source
|
94
|
-
end
|
95
69
|
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
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"
|
103
135
|
end
|
104
136
|
end
|
105
137
|
end
|
138
|
+
end
|
139
|
+
|
140
|
+
def initialize file = SOURCE_FILE, indent: 0
|
141
|
+
file, @indent = (Pathname file), indent
|
106
142
|
|
107
|
-
|
143
|
+
*chain, last = file.basename.to_s.split '.'
|
144
|
+
name = last.upcase
|
145
|
+
source = file.read
|
146
|
+
dir = file.dirname
|
147
|
+
|
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."
|
152
|
+
end
|
153
|
+
|
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
|
108
160
|
end
|
109
161
|
|
110
|
-
class
|
111
|
-
def initialize
|
112
|
-
@
|
113
|
-
@scope =
|
114
|
-
when Array
|
115
|
-
scope
|
116
|
-
when String
|
117
|
-
eval scope
|
118
|
-
end
|
162
|
+
class Write
|
163
|
+
def initialize config
|
164
|
+
@file = Pathname config.output
|
165
|
+
@scope = config.scope
|
119
166
|
end
|
120
167
|
|
121
|
-
|
122
|
-
|
168
|
+
attr_reader :file
|
169
|
+
|
170
|
+
def [] string
|
171
|
+
file.dirname.mkpath
|
123
172
|
|
124
173
|
if @scope
|
125
|
-
@scope.
|
126
|
-
string = "#{
|
174
|
+
@scope.each do |header|
|
175
|
+
string = "#{header}\n#{string.indent INDENT}\nend"
|
127
176
|
end
|
128
177
|
end
|
129
178
|
|
130
|
-
|
131
|
-
end
|
132
|
-
|
133
|
-
def file
|
134
|
-
@path
|
179
|
+
file.write "#{string}\n"
|
135
180
|
end
|
136
181
|
end
|
137
182
|
end
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bgem
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.13
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
- Anatoly
|
7
|
+
- Anatoly Chernov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
12
|
-
dependencies:
|
11
|
+
date: 2021-04-29 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: string-indent
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.0.1
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.0.1
|
13
27
|
description:
|
14
28
|
email:
|
15
29
|
executables:
|
@@ -19,8 +33,9 @@ extra_rdoc_files: []
|
|
19
33
|
files:
|
20
34
|
- bin/bgem
|
21
35
|
- lib/bgem.rb
|
22
|
-
homepage:
|
23
|
-
licenses:
|
36
|
+
homepage: https://github.com/ch1c0t/bgem
|
37
|
+
licenses:
|
38
|
+
- ISC
|
24
39
|
metadata: {}
|
25
40
|
post_install_message:
|
26
41
|
rdoc_options: []
|
@@ -37,9 +52,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
37
52
|
- !ruby/object:Gem::Version
|
38
53
|
version: '0'
|
39
54
|
requirements: []
|
40
|
-
|
41
|
-
rubygems_version: 2.6.8
|
55
|
+
rubygems_version: 3.1.6
|
42
56
|
signing_key:
|
43
57
|
specification_version: 4
|
44
|
-
summary:
|
58
|
+
summary: A tool to build single-file Ruby gems with less ends.
|
45
59
|
test_files: []
|