bgem 0.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +2 -0
- data/Gemfile +5 -0
- data/bgem.gemspec +9 -0
- data/bin/bgem +4 -0
- data/lib/bgem.rb +11 -0
- data/lib/bgem/cli.rb +18 -0
- data/lib/bgem/source_file.rb +36 -0
- data/lib/bgem/target_file.rb +12 -0
- data/spec/bgem_spec.rb +15 -0
- data/spec/helper.rb +15 -0
- data/spec/test_src/Main.module.rb +1 -0
- data/spec/test_src/after.Main/After.class.rb +1 -0
- data/spec/test_src/after.Main/AfterModule.module.rb +1 -0
- data/spec/test_src/before.Main/Before.module.rb +1 -0
- data/spec/test_src/before.Main/before.Before/Inside.class.rb +1 -0
- metadata +58 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 63d339840b4211fef494fa54cae3a688c67271ba
|
4
|
+
data.tar.gz: a7521c7db2767fd2cc67384cd3dc9a0f0b92a662
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 81c88e6476c909372d33ec2ace1d18c5337ce3f55b77cfb28a914f9c750efde7b94271ca60554273e6850ca6e4b2ec026add36cd1083136dda74ca6f03ad80da
|
7
|
+
data.tar.gz: c7493723761256b417c11027b70b23c55bc45241e44393139b80b303815b7f740a292322123f4c771d3cdd351ff4c95b053a77d4ec04d3f260a15872b6ec4ef6
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/bgem.gemspec
ADDED
data/bin/bgem
ADDED
data/lib/bgem.rb
ADDED
data/lib/bgem/cli.rb
ADDED
@@ -0,0 +1,18 @@
|
|
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
|
@@ -0,0 +1,36 @@
|
|
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/spec/bgem_spec.rb
ADDED
@@ -0,0 +1,15 @@
|
|
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
ADDED
@@ -0,0 +1,15 @@
|
|
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
|
@@ -0,0 +1 @@
|
|
1
|
+
class_method_inside_Main_module
|
@@ -0,0 +1 @@
|
|
1
|
+
in_after_class
|
@@ -0,0 +1 @@
|
|
1
|
+
in after module
|
@@ -0,0 +1 @@
|
|
1
|
+
in before
|
@@ -0,0 +1 @@
|
|
1
|
+
in inside
|
metadata
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bgem
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Anatoly Chernow
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-01-06 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description:
|
14
|
+
email:
|
15
|
+
executables:
|
16
|
+
- bgem
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- ".gitignore"
|
21
|
+
- Gemfile
|
22
|
+
- bgem.gemspec
|
23
|
+
- bin/bgem
|
24
|
+
- 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
|
+
homepage:
|
36
|
+
licenses: []
|
37
|
+
metadata: {}
|
38
|
+
post_install_message:
|
39
|
+
rdoc_options: []
|
40
|
+
require_paths:
|
41
|
+
- lib
|
42
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- - ">="
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: '0'
|
52
|
+
requirements: []
|
53
|
+
rubyforge_project:
|
54
|
+
rubygems_version: 2.5.2
|
55
|
+
signing_key:
|
56
|
+
specification_version: 4
|
57
|
+
summary: Build gems without too much hassle.
|
58
|
+
test_files: []
|