bgem-new 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/Gemfile +9 -0
- data/Gemfile.lock +47 -0
- data/bgem-new.gemspec +11 -0
- data/bin/bgem-new +4 -0
- data/lib/bgem/lib.rb +66 -0
- data/lib/bgem/new.rb +20 -0
- data/lib/bgem/print_help.rb +26 -0
- data/lib/bgem/string.rb +19 -0
- data/lib/bgem/templates/Gemfile +11 -0
- data/lib/bgem/templates/Rakefile +13 -0
- data/lib/bgem/templates/bgem-config.nested.erb +5 -0
- data/lib/bgem/templates/bgem-config.top.erb +1 -0
- data/lib/bgem/templates/gemspec.erb +9 -0
- data/lib/bgem/templates/gitignore +3 -0
- data/lib/bgem/templates/main_spec.nested.erb +9 -0
- data/lib/bgem/templates/main_spec.top.erb +7 -0
- data/lib/bgem/templates/module_stub.rb +3 -0
- data/lib/bgem/templates/rspec-helper.nested.erb +5 -0
- data/lib/bgem/templates/rspec-helper.top.erb +5 -0
- metadata +62 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 943eb1c6f6d3f90a5d2eef3821c92ce3547163b27138bdd68b8a6adb08fb909b
|
4
|
+
data.tar.gz: a16e260650b2e9332f85dab1495f22fdbfa53801957b921d5a189fdb230adbfb
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: bb6b525d0271afe5345bacd8e79c0bb995bc758448e145ac645b88ef2e4412c5e09117a247ab9e3a109181a20742f90445c59e7c35a5caa0d7d7cdb04c3a5be4
|
7
|
+
data.tar.gz: 9f079e75df03c475aba11345a14e2a3130f264500bcf72af10df766f0517bdb38484bc6fe4eaf8c0387b1b87d1b390eb5de9dbc30d422a9fb69d55956b8a4480
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
bgem-new (0.0.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
awesome_print (1.9.2)
|
10
|
+
coderay (1.1.3)
|
11
|
+
diff-lcs (1.5.0)
|
12
|
+
method_source (1.0.0)
|
13
|
+
power_assert (2.0.3)
|
14
|
+
pry (0.14.2)
|
15
|
+
coderay (~> 1.1)
|
16
|
+
method_source (~> 1.0)
|
17
|
+
rake (13.0.6)
|
18
|
+
rspec (3.12.0)
|
19
|
+
rspec-core (~> 3.12.0)
|
20
|
+
rspec-expectations (~> 3.12.0)
|
21
|
+
rspec-mocks (~> 3.12.0)
|
22
|
+
rspec-core (3.12.2)
|
23
|
+
rspec-support (~> 3.12.0)
|
24
|
+
rspec-expectations (3.12.3)
|
25
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
26
|
+
rspec-support (~> 3.12.0)
|
27
|
+
rspec-mocks (3.12.6)
|
28
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
29
|
+
rspec-support (~> 3.12.0)
|
30
|
+
rspec-power_assert (1.2.0)
|
31
|
+
power_assert (~> 2.0)
|
32
|
+
rspec (>= 2.14)
|
33
|
+
rspec-support (3.12.1)
|
34
|
+
|
35
|
+
PLATFORMS
|
36
|
+
x86_64-linux
|
37
|
+
|
38
|
+
DEPENDENCIES
|
39
|
+
awesome_print
|
40
|
+
bgem-new!
|
41
|
+
pry
|
42
|
+
rake
|
43
|
+
rspec
|
44
|
+
rspec-power_assert
|
45
|
+
|
46
|
+
BUNDLED WITH
|
47
|
+
2.4.15
|
data/bgem-new.gemspec
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
Gem::Specification.new do |g|
|
2
|
+
g.name = 'bgem-new'
|
3
|
+
g.files = `git ls-files`.split($/)
|
4
|
+
g.version = '0.0.0'
|
5
|
+
g.summary = 'A CLI to generate new Bgem projects.'
|
6
|
+
g.authors = ['Anatoly Chernov']
|
7
|
+
g.license = 'ISC'
|
8
|
+
g.homepage = 'https://github.com/ch1c0t/bgem-new'
|
9
|
+
|
10
|
+
g.executables << 'bgem-new'
|
11
|
+
end
|
data/bin/bgem-new
ADDED
data/lib/bgem/lib.rb
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
require_relative 'string'
|
2
|
+
|
3
|
+
module Bgem
|
4
|
+
module New
|
5
|
+
class Lib
|
6
|
+
def initialize name
|
7
|
+
@name = name
|
8
|
+
@constants = @name.split ':'
|
9
|
+
@gem_name = @name.to_gem_name
|
10
|
+
@root = "#{Dir.pwd}/#{@gem_name}"
|
11
|
+
|
12
|
+
create
|
13
|
+
end
|
14
|
+
|
15
|
+
def create
|
16
|
+
create_common
|
17
|
+
|
18
|
+
if @constants.size > 1
|
19
|
+
create_for_nested_constant
|
20
|
+
else
|
21
|
+
create_for_top_constant
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
TEMPLATES = "#{__dir__}/templates"
|
26
|
+
|
27
|
+
def create_common
|
28
|
+
Dir.mkdir @root
|
29
|
+
IO.write "#{@root}/#{@gem_name}.gemspec", (template :gemspec)
|
30
|
+
|
31
|
+
copy "#{TEMPLATES}/Gemfile", "#{@root}/Gemfile"
|
32
|
+
copy "#{TEMPLATES}/Rakefile", "#{@root}/Rakefile"
|
33
|
+
copy "#{TEMPLATES}/gitignore", "#{@root}/.gitignore"
|
34
|
+
|
35
|
+
Dir.mkdir "#{@root}/src"
|
36
|
+
Dir.mkdir "#{@root}/bgem"
|
37
|
+
Dir.mkdir "#{@root}/spec"
|
38
|
+
end
|
39
|
+
|
40
|
+
def create_for_top_constant
|
41
|
+
copy "#{TEMPLATES}/module_stub.rb", "#{@root}/src/#{@name}.module.rb"
|
42
|
+
IO.write "#{@root}/bgem/config.rb", (template 'bgem-config.top')
|
43
|
+
IO.write "#{@root}/spec/helper.rb", (template 'rspec-helper.top')
|
44
|
+
IO.write "#{@root}/spec/main_spec.rb", (template 'main_spec.top')
|
45
|
+
end
|
46
|
+
|
47
|
+
def create_for_nested_constant
|
48
|
+
copy "#{TEMPLATES}/module_stub.rb", "#{@root}/src/#{@constants.last}.module.rb"
|
49
|
+
IO.write "#{@root}/bgem/config.rb", (template 'bgem-config.nested')
|
50
|
+
IO.write "#{@root}/spec/helper.rb", (template 'rspec-helper.nested')
|
51
|
+
IO.write "#{@root}/spec/main_spec.rb", (template 'main_spec.nested')
|
52
|
+
end
|
53
|
+
|
54
|
+
def template template_name
|
55
|
+
require 'erb'
|
56
|
+
renderer = ERB.new IO.read "#{TEMPLATES}/#{template_name}.erb"
|
57
|
+
renderer.result binding
|
58
|
+
end
|
59
|
+
|
60
|
+
def copy from, to
|
61
|
+
require 'fileutils'
|
62
|
+
FileUtils.cp from, to
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
data/lib/bgem/new.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
module Bgem
|
2
|
+
module New
|
3
|
+
def self.run
|
4
|
+
command, name = ARGV
|
5
|
+
|
6
|
+
case command
|
7
|
+
when nil
|
8
|
+
require_relative 'print_help'
|
9
|
+
print_help
|
10
|
+
when 'lib'
|
11
|
+
require_relative 'lib'
|
12
|
+
Lib.new name
|
13
|
+
when 'cli'
|
14
|
+
p 'Not implemented yet.'
|
15
|
+
else
|
16
|
+
p "Unknown command #{command}."
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Bgem
|
2
|
+
module New
|
3
|
+
def self.print_help
|
4
|
+
puts <<~S
|
5
|
+
A CLI to generate new Bgem projects.
|
6
|
+
|
7
|
+
Usage:
|
8
|
+
bgem-new TYPE NAME
|
9
|
+
|
10
|
+
For example:
|
11
|
+
bgem-new lib SomeConstant
|
12
|
+
|
13
|
+
TYPE: the type of the project to be generated.
|
14
|
+
Possible values:
|
15
|
+
lib
|
16
|
+
cli
|
17
|
+
NAME: the name of the constant to be worked on in the project.
|
18
|
+
Nested constants should be given using ':' as a delimiter.
|
19
|
+
|
20
|
+
For example:
|
21
|
+
Constant
|
22
|
+
Constant:InSomeNested:Namespace
|
23
|
+
S
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/lib/bgem/string.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
class String
|
2
|
+
def to_snake_case
|
3
|
+
self
|
4
|
+
.gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
|
5
|
+
.gsub(/([a-z\d])([A-Z])/, '\1_\2')
|
6
|
+
.downcase
|
7
|
+
end
|
8
|
+
|
9
|
+
def to_gem_name
|
10
|
+
parts = self.split(':')
|
11
|
+
|
12
|
+
if parts.size > 1
|
13
|
+
parts.map(&:to_snake_case).join '-'
|
14
|
+
else
|
15
|
+
self.to_snake_case
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
@@ -0,0 +1 @@
|
|
1
|
+
output 'lib/<%= @gem_name %>.rb'
|
metadata
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bgem-new
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Anatoly Chernov
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-07-24 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description:
|
14
|
+
email:
|
15
|
+
executables:
|
16
|
+
- bgem-new
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- Gemfile
|
21
|
+
- Gemfile.lock
|
22
|
+
- bgem-new.gemspec
|
23
|
+
- bin/bgem-new
|
24
|
+
- lib/bgem/lib.rb
|
25
|
+
- lib/bgem/new.rb
|
26
|
+
- lib/bgem/print_help.rb
|
27
|
+
- lib/bgem/string.rb
|
28
|
+
- lib/bgem/templates/Gemfile
|
29
|
+
- lib/bgem/templates/Rakefile
|
30
|
+
- lib/bgem/templates/bgem-config.nested.erb
|
31
|
+
- lib/bgem/templates/bgem-config.top.erb
|
32
|
+
- lib/bgem/templates/gemspec.erb
|
33
|
+
- lib/bgem/templates/gitignore
|
34
|
+
- lib/bgem/templates/main_spec.nested.erb
|
35
|
+
- lib/bgem/templates/main_spec.top.erb
|
36
|
+
- lib/bgem/templates/module_stub.rb
|
37
|
+
- lib/bgem/templates/rspec-helper.nested.erb
|
38
|
+
- lib/bgem/templates/rspec-helper.top.erb
|
39
|
+
homepage: https://github.com/ch1c0t/bgem-new
|
40
|
+
licenses:
|
41
|
+
- ISC
|
42
|
+
metadata: {}
|
43
|
+
post_install_message:
|
44
|
+
rdoc_options: []
|
45
|
+
require_paths:
|
46
|
+
- lib
|
47
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- - ">="
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: '0'
|
52
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '0'
|
57
|
+
requirements: []
|
58
|
+
rubygems_version: 3.4.15
|
59
|
+
signing_key:
|
60
|
+
specification_version: 4
|
61
|
+
summary: A CLI to generate new Bgem projects.
|
62
|
+
test_files: []
|