stub_gem 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: f72e4d67faf167af670866c1a64bf5a238057d3702c618da37affd337dbcdeef
4
+ data.tar.gz: 2536a6a972a2b25727a51b2c8f7bc02bb2ed161cb55464e33a5e76c25c3cf5bb
5
+ SHA512:
6
+ metadata.gz: c97ffbced2b9dbdd9a56a092d4d00e49a0d822e089dda34c407bb16de4642c4ad5ed04ef6fd4379b72b48fa26f168527bfa18fe094634bc578c3bd89a75e56c3
7
+ data.tar.gz: 1940fbbc63f7d7ddab1964d1d284211f6c80283b84b076b08938a395d302ee269d449309da1dc6089457628d69ae4fa221163c8c3fded8456be5d61a239c6017
data/.rubocop.yml ADDED
@@ -0,0 +1,2 @@
1
+ inherit_gem:
2
+ dc-rubocop: default.yml
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gemspec
6
+
7
+ group :development, optional: true do
8
+ gem "dc-devtools"
9
+ end
data/Guardfile ADDED
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ directories(%w[. lib test].select { |d| Dir.exist?(d) ? d : UI.warning("Directory #{d} does not exist") })
4
+
5
+ guard :rake, task: "default" do
6
+ watch("Gemfile")
7
+ watch("Rakefile")
8
+ watch("Guardfile")
9
+ watch(%r{^test/helper\.rb$})
10
+ watch(%r{^test/test_(.*)\.rb$})
11
+ watch(%r{^lib/<%= @project_name %>/(.*)\.rb$})
12
+ watch(%r{^lib/(.*)\.rb$})
13
+ end
data/README.md ADDED
@@ -0,0 +1,5 @@
1
+ I wanted a program to template out a basic Ruby project, so that all the
2
+ project setup is "just there" and I don't have to think about what parts I'm
3
+ missing - everything is already "at hand," it's just a matter of me drumming
4
+ something up. Project templates are nothing new, but this is my little
5
+ contribution to the field.
data/Rakefile ADDED
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rake/testtask"
5
+ require "rubocop/rake_task"
6
+
7
+ Rake::TestTask.new(:test) do |t|
8
+ t.libs << "test"
9
+ t.libs << "lib"
10
+ t.test_files = FileList["test/test_*.rb"]
11
+ end
12
+
13
+ RuboCop::RakeTask.new
14
+
15
+ task default: %i[test rubocop]
data/exe/stub_gem ADDED
@@ -0,0 +1,21 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "stub_gem"
5
+
6
+ def fail_usage(msg)
7
+ errormsg = <<~MSG
8
+ ERROR #{msg}
9
+ stub_gem
10
+ Usage:
11
+ stub_gem $PROJECT_NAME
12
+ MSG
13
+ abort errormsg
14
+ end
15
+
16
+ # TODO: use OptionParser or something nice like that
17
+ proj_name = ARGV[0]
18
+ fail_usage "Need a project name before proceeding" unless proj_name
19
+ puts "* Project name: #{proj_name}"
20
+
21
+ StubGem::RubyProject.new proj_name, "#{Dir.home}/src/#{proj_name}"
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module StubGem
4
+ VERSION = "0.0.1"
5
+ end
data/lib/stub_gem.rb ADDED
@@ -0,0 +1,135 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "pathname"
5
+ require "fileutils"
6
+ require "date"
7
+ require "erb"
8
+
9
+ module StubGem
10
+ class RubyProject
11
+ def initialize(project_name, base_path)
12
+ @year = Date.today.year
13
+ @author = "David Crosby"
14
+ @project_name = project_name
15
+ @project_class = @project_name.capitalize
16
+
17
+ puts "* Using #{base_path}"
18
+ @template_dir = "#{File.dirname(Pathname.new(__FILE__).realpath)}/../templates/"
19
+ puts "* Template dir of #{@template_dir}"
20
+ fail_usage "project folder location exists at #{base_path}" if Dir.exist? base_path
21
+ @base_path_str = base_path
22
+ stub_project
23
+ end
24
+
25
+ def project_class
26
+ @project_class ||= @project_name.capitalize
27
+ end
28
+
29
+ def stub_project
30
+ Dir.mkdir @base_path_str
31
+ dir = Dir.new @base_path_str
32
+ @base_path = "#{dir.path}/"
33
+ puts "* Base path of: #{@base_path}"
34
+
35
+ stub_directory_structure
36
+ stub_project_docs
37
+ stub_library_mgmt
38
+ stub_testing
39
+ stub_build_infra
40
+ stub_linters
41
+ stub_code_boilerplate
42
+ stub_version_control
43
+ end
44
+
45
+ def stub_directory_structure
46
+ [
47
+ "lib/#{@project_name}",
48
+ ".github/workflows",
49
+ ".bundle",
50
+ "bin",
51
+ "test"
52
+ ].each do |dir|
53
+ FileUtils.mkdir_p("#{@base_path}/#{dir}")
54
+ end
55
+ end
56
+
57
+ def stub_project_docs
58
+ # TODO: stub_contributors
59
+ %w[
60
+ README.md
61
+ TODO.md
62
+ LICENSE
63
+ ].each do |f|
64
+ stub_single_file(f)
65
+ end
66
+ end
67
+
68
+ def stub_testing
69
+ # TODO: stub_minitest
70
+ end
71
+
72
+ def stub_library_mgmt
73
+ %w[
74
+ Gemfile
75
+ ].each do |f|
76
+ stub_single_file(f)
77
+ end
78
+ [
79
+ ["Gemfile"],
80
+ ["gemspec", nil, "#{@project_name}.gemspec"]
81
+ ].each do |name, dir, desired_name|
82
+ stub_single_file name, dir, desired_name
83
+ end
84
+ end
85
+
86
+ def stub_build_infra
87
+ [
88
+ ["Rakefile"],
89
+ ["Guardfile"],
90
+ ["bundle_config", ".bundle", "config"]
91
+ ].each do |name, dir, desired_name|
92
+ stub_single_file name, dir, desired_name
93
+ end
94
+ end
95
+
96
+ def stub_linters
97
+ %w[
98
+ .rubocop.yml
99
+ ].each do |f|
100
+ stub_single_file(f)
101
+ end
102
+ end
103
+
104
+ def stub_code_boilerplate
105
+ [
106
+ ["base_lib.rb.erb", "lib", "#{@project_name}.rb"],
107
+ ["version.rb.erb", "lib/#{@project_name}", "version.rb"]
108
+ ].each do |name, dir, desired_name|
109
+ stub_single_file name, dir, desired_name
110
+ end
111
+ end
112
+
113
+ def stub_version_control
114
+ [
115
+ [".gitignore"],
116
+ ["ruby_gh_workflow.yml", ".github/workflows", "main.yml"]
117
+ ].each do |name, dir, desired_name|
118
+ stub_single_file name, dir, desired_name
119
+ end
120
+ # TODO: stub_gitcommit
121
+ # TODO stub_github_project_templates
122
+ end
123
+
124
+ def stub_single_file(name, dir=nil, desired_name=nil)
125
+ template = ERB.new(File.read(File.join(@template_dir, name)))
126
+ desired_name ||= name
127
+ filepath = "#{@base_path}/"
128
+ filepath << "#{dir}/" if dir
129
+ filepath << desired_name
130
+ f = File.new(filepath, "w")
131
+ f.write(template.result(binding))
132
+ f.close
133
+ end
134
+ end
135
+ end
@@ -0,0 +1,3 @@
1
+ vendor
2
+ .bundle
3
+ Gemfile.lock
@@ -0,0 +1,5 @@
1
+ inherit_gem:
2
+ dc-rubocop: default.yml
3
+
4
+ AllCops:
5
+ TargetRubyVersion: 2.5
data/templates/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gemspec
6
+
7
+ group :development, optional: true do
8
+ gem "dc-devtools"
9
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ directories(%w[. lib test].select { |d| Dir.exist?(d) ? d : UI.warning("Directory #{d} does not exist") })
4
+
5
+ guard :rake, task: "default" do
6
+ watch("Gemfile")
7
+ watch("Rakefile")
8
+ watch("Guardfile")
9
+ watch(%r{^test/helper\.rb$})
10
+ watch(%r{^test/test_(.*)\.rb$})
11
+ watch(%r{^lib/<%= @project_name %>/(.*)\.rb$})
12
+ watch(%r{^lib/(.*)\.rb$})
13
+ end
data/templates/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) <%= @year %> <%= @author %>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,15 @@
1
+ # <%= @project_name %>
2
+
3
+ What is this project?
4
+
5
+ ## Usage
6
+
7
+ TODO!
8
+
9
+ ## Contributing
10
+
11
+ TODO!
12
+
13
+ ## License
14
+
15
+ See LICENSE file
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rake/testtask"
5
+ require "rubocop/rake_task"
6
+
7
+ Rake::TestTask.new(:test) do |t|
8
+ t.libs << "test"
9
+ t.libs << "lib"
10
+ t.test_files = FileList["test/test_*.rb"]
11
+ end
12
+
13
+ RuboCop::RakeTask.new
14
+
15
+ task default: %i[test rubocop]
data/templates/TODO.md ADDED
@@ -0,0 +1,6 @@
1
+ - [ ] Upload `<%= @project_name %>` to RubyGems (TODO command?)
2
+ - [ ] Scrub git repo (TODO put command to merge commits into "initial commit")
3
+ - [ ] Upload git repo to Github (TODO link to "create new repo")
4
+ - [ ] Write a quick blog post
5
+ - [ ] Post link to HN (TODO link to thing)
6
+ - [ ] Post link to lobste.rs
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "<%= @project_name %>/version"
4
+
5
+ module <%= @project_class %>
6
+ # TODO
7
+ end
@@ -0,0 +1,2 @@
1
+ ---
2
+ BUNDLE_WITH: "development"
data/templates/gemspec ADDED
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/<%= @project_name %>/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "<%= @project_name %>"
7
+ spec.required_ruby_version = ">= 2.5.0"
8
+ spec.version = <%= @project_class %>::VERSION
9
+ spec.platform = Gem::Platform::RUBY
10
+ spec.authors = ["David Crosby"]
11
+ spec.homepage = "https://daveops.net"
12
+ spec.summary = "A fancy new gem"
13
+ spec.description = "A fancy new gem generated by stub_gem"
14
+ spec.license = "MIT"
15
+ spec.metadata["homepage_uri"] = spec.homepage
16
+ spec.metadata["rubygems_mfa_required"] = "true"
17
+
18
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
19
+ `git ls-files -z`.split("\x0").reject do |f|
20
+ (f == __FILE__) || f.match(%r{\A(?:(?:bin|test)/|\.(?:git))})
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,30 @@
1
+ name: Ruby
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - main
7
+
8
+ pull_request:
9
+
10
+ jobs:
11
+ build:
12
+ runs-on: ubuntu-latest
13
+ name: Ruby ${{ matrix.ruby }}
14
+ env:
15
+ BUNDLE_WITH: development
16
+ strategy:
17
+ matrix:
18
+ ruby:
19
+ - '2.6'
20
+ - '3.0'
21
+
22
+ steps:
23
+ - uses: actions/checkout@v2
24
+ - name: Set up Ruby
25
+ uses: ruby/setup-ruby@v1
26
+ with:
27
+ ruby-version: ${{ matrix.ruby }}
28
+ bundler-cache: true
29
+ - name: Run the default task
30
+ run: bundle exec rake
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module <%= @project_class %>
4
+ VERSION = "0.0.1"
5
+ end
metadata ADDED
@@ -0,0 +1,65 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: stub_gem
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - David Crosby
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-07-26 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Simple program to stub out a Ruby project how I like it
14
+ email:
15
+ executables:
16
+ - stub_gem
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - ".rubocop.yml"
21
+ - Gemfile
22
+ - Guardfile
23
+ - README.md
24
+ - Rakefile
25
+ - exe/stub_gem
26
+ - lib/stub_gem.rb
27
+ - lib/stub_gem/version.rb
28
+ - templates/.gitignore
29
+ - templates/.rubocop.yml
30
+ - templates/Gemfile
31
+ - templates/Guardfile
32
+ - templates/LICENSE
33
+ - templates/README.md
34
+ - templates/Rakefile
35
+ - templates/TODO.md
36
+ - templates/base_lib.rb.erb
37
+ - templates/bundle_config
38
+ - templates/gemspec
39
+ - templates/ruby_gh_workflow.yml
40
+ - templates/version.rb.erb
41
+ homepage: https://daveops.net
42
+ licenses:
43
+ - MIT
44
+ metadata:
45
+ rubygems_mfa_required: 'true'
46
+ post_install_message:
47
+ rdoc_options: []
48
+ require_paths:
49
+ - lib
50
+ required_ruby_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: 2.6.0
55
+ required_rubygems_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ requirements: []
61
+ rubygems_version: 3.3.7
62
+ signing_key:
63
+ specification_version: 4
64
+ summary: Simple program to stub out a Ruby project how I like it
65
+ test_files: []