bgem 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/bgem.rb +71 -8
- metadata +2 -15
- data/.gitignore +0 -2
- data/Gemfile +0 -5
- data/bgem.gemspec +0 -9
- data/lib/bgem/cli.rb +0 -18
- data/lib/bgem/source_file.rb +0 -36
- data/lib/bgem/target_file.rb +0 -12
- data/spec/bgem_spec.rb +0 -15
- data/spec/helper.rb +0 -15
- data/spec/test_src/Main.module.rb +0 -1
- data/spec/test_src/after.Main/After.class.rb +0 -1
- data/spec/test_src/after.Main/AfterModule.module.rb +0 -1
- data/spec/test_src/before.Main/Before.module.rb +0 -1
- data/spec/test_src/before.Main/before.Before/Inside.class.rb +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eac187349299661854ca19def82c05e8abb8100a
|
4
|
+
data.tar.gz: 9d227807b5776bba0a66d7a58c20a80bb201055b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1b9b60f6c13811f3c3c4a9082d694d9003ece5140a16638bb6f3e3629e13580337f7d45ff8851b323b46663fc5d146c2e3a8e1bcf3a1106d4c573644af236d7b
|
7
|
+
data.tar.gz: 0de32c5845c033abb8e0d8347674d8c11222ccb4cb9d69eb8587fb1f5d80efd63cb91f590a96aa407ba7e1d9c420ff796ee2b4487d8d566907725702dd9a687f
|
data/lib/bgem.rb
CHANGED
@@ -1,11 +1,74 @@
|
|
1
|
-
|
1
|
+
module Bgem
|
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
|
+
}
|
2
11
|
|
3
|
-
|
4
|
-
|
5
|
-
|
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
|
6
27
|
end
|
7
|
-
end
|
8
28
|
|
9
|
-
|
10
|
-
|
11
|
-
|
29
|
+
class SourceFile
|
30
|
+
INDENT = 2
|
31
|
+
|
32
|
+
def initialize file, indent: 0
|
33
|
+
@file, @indent = (Pathname file), indent
|
34
|
+
@source = @file.read
|
35
|
+
@constant, @type, _rb = @file.basename.to_s.split '.'
|
36
|
+
end
|
37
|
+
|
38
|
+
def to_s
|
39
|
+
"#{@type} #{@constant}\n#{source}end".indent @indent
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
def source
|
44
|
+
source = @source.indent INDENT
|
45
|
+
source.prepend "#{before}\n\n" unless before.empty?
|
46
|
+
source.concat "\n#{after}\n" unless after.empty?
|
47
|
+
source
|
48
|
+
end
|
49
|
+
|
50
|
+
def self.concatenate_source_files *symbols
|
51
|
+
symbols.each do |symbol|
|
52
|
+
define_method symbol do
|
53
|
+
pattern = @file.dirname.join "#{__method__}.#{@constant}/*.rb"
|
54
|
+
Pathname.glob(pattern).map do |file|
|
55
|
+
self.class.new(file, indent: INDENT).to_s
|
56
|
+
end.join "\n\n"
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
concatenate_source_files :before, :after
|
62
|
+
end
|
63
|
+
|
64
|
+
class TargetFile
|
65
|
+
def initialize path
|
66
|
+
@path = Pathname path
|
67
|
+
end
|
68
|
+
|
69
|
+
def write string
|
70
|
+
@path.dirname.mkpath
|
71
|
+
@path.write string
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
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.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Anatoly Chernow
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-01-
|
11
|
+
date: 2017-01-07 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email:
|
@@ -17,21 +17,8 @@ executables:
|
|
17
17
|
extensions: []
|
18
18
|
extra_rdoc_files: []
|
19
19
|
files:
|
20
|
-
- ".gitignore"
|
21
|
-
- Gemfile
|
22
|
-
- bgem.gemspec
|
23
20
|
- bin/bgem
|
24
21
|
- lib/bgem.rb
|
25
|
-
- lib/bgem/cli.rb
|
26
|
-
- lib/bgem/source_file.rb
|
27
|
-
- lib/bgem/target_file.rb
|
28
|
-
- spec/bgem_spec.rb
|
29
|
-
- spec/helper.rb
|
30
|
-
- spec/test_src/Main.module.rb
|
31
|
-
- spec/test_src/after.Main/After.class.rb
|
32
|
-
- spec/test_src/after.Main/AfterModule.module.rb
|
33
|
-
- spec/test_src/before.Main/Before.module.rb
|
34
|
-
- spec/test_src/before.Main/before.Before/Inside.class.rb
|
35
22
|
homepage:
|
36
23
|
licenses: []
|
37
24
|
metadata: {}
|
data/.gitignore
DELETED
data/Gemfile
DELETED
data/bgem.gemspec
DELETED
data/lib/bgem/cli.rb
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
module Bgem
|
2
|
-
module CLI
|
3
|
-
MAIN_FILE = Dir['src/*.rb'][0]
|
4
|
-
|
5
|
-
def self.run
|
6
|
-
options = parse_argv
|
7
|
-
target = TargetFile.new (options[:output] || 'output.rb')
|
8
|
-
target.write SourceFile.new(options[:input] || MAIN_FILE).to_s
|
9
|
-
end
|
10
|
-
|
11
|
-
def self.parse_argv
|
12
|
-
ARGV.map do |string|
|
13
|
-
key, _colon, value = string.partition ':'
|
14
|
-
[key.to_sym, value]
|
15
|
-
end.to_h
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
data/lib/bgem/source_file.rb
DELETED
@@ -1,36 +0,0 @@
|
|
1
|
-
module Bgem
|
2
|
-
class SourceFile
|
3
|
-
INDENT = 2
|
4
|
-
|
5
|
-
def initialize file, indent: 0
|
6
|
-
@file, @indent = (Pathname file), indent
|
7
|
-
@source = @file.read
|
8
|
-
@constant, @type, _rb = @file.basename.to_s.split '.'
|
9
|
-
end
|
10
|
-
|
11
|
-
def to_s
|
12
|
-
"#{@type} #{@constant}\n#{source}end".indent @indent
|
13
|
-
end
|
14
|
-
|
15
|
-
private
|
16
|
-
def source
|
17
|
-
source = @source.indent INDENT
|
18
|
-
source.prepend "#{before}\n\n" unless before.empty?
|
19
|
-
source.concat "\n#{after}\n" unless after.empty?
|
20
|
-
source
|
21
|
-
end
|
22
|
-
|
23
|
-
def self.concatenate_source_files *symbols
|
24
|
-
symbols.each do |symbol|
|
25
|
-
define_method symbol do
|
26
|
-
pattern = @file.dirname.join "#{__method__}.#{@constant}/*.rb"
|
27
|
-
Pathname.glob(pattern).map do |file|
|
28
|
-
self.class.new(file, indent: INDENT).to_s
|
29
|
-
end.join "\n\n"
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
concatenate_source_files :before, :after
|
35
|
-
end
|
36
|
-
end
|
data/lib/bgem/target_file.rb
DELETED
data/spec/bgem_spec.rb
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
describe do
|
4
|
-
it do
|
5
|
-
output = OUTPUT.read.lines
|
6
|
-
|
7
|
-
assert { output[0] == "module Main\n" }
|
8
|
-
assert { output[1] == " module Before\n" }
|
9
|
-
assert { output[2] == " class Inside\n" }
|
10
|
-
assert { output[3] == " in inside\n" }
|
11
|
-
assert { output[6] == " in before\n" }
|
12
|
-
|
13
|
-
assert { output[11] == " class After\n" }
|
14
|
-
end
|
15
|
-
end
|
data/spec/helper.rb
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
require 'hobby/devtools/rspec_helper'
|
2
|
-
require 'bgem'
|
3
|
-
|
4
|
-
INPUT = Pathname "spec/test_src/Main.module.rb"
|
5
|
-
OUTPUT = Pathname "/tmp/rspec.bgem.#{$$}/output.rb"
|
6
|
-
|
7
|
-
module Bgem
|
8
|
-
module CLI
|
9
|
-
def self.parse_argv
|
10
|
-
{ input: INPUT, output: OUTPUT }
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
Bgem::CLI.run
|
@@ -1 +0,0 @@
|
|
1
|
-
class_method_inside_Main_module
|
@@ -1 +0,0 @@
|
|
1
|
-
in_after_class
|
@@ -1 +0,0 @@
|
|
1
|
-
in after module
|
@@ -1 +0,0 @@
|
|
1
|
-
in before
|
@@ -1 +0,0 @@
|
|
1
|
-
in inside
|