rsgem 0.1.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: f0622fb3d78fdde2291dddba96eb5ec6dbebc8be9bf32187a6c76374c48a4428
4
+ data.tar.gz: 926cbc4d4003bb8c214a4894def1325b596487e0e73c21a0247df10bbf8ad0dd
5
+ SHA512:
6
+ metadata.gz: 5b429ae00a6454f4f110576467bb556913db2b0c870075bff02d1bb7ad0c41ed0eb8e8158727b31c1bac8e1abc90fdf13a1ead4b8ce858b8d154cf1bfa0a67f3
7
+ data.tar.gz: 8b41cbcf3c7e1ef59db574885631201fd85ee745b986b9e4bba2b7aacc55d71edfb2ee2422d66a2faf5c93d22c9ab53932e9fe743e6b950c45d8fbc7a6cbee3c
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Juan Manuel Ramallo
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
13
+ all 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
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,84 @@
1
+ # `rsgem` - Rootstrap's gem generator
2
+
3
+ ![build](https://github.com/rootstrap/rsgem/workflows/build/badge.svg)
4
+ [![Maintainability](https://api.codeclimate.com/v1/badges/c22da1693543a6eac7e9/maintainability)](https://codeclimate.com/github/rootstrap/rsgem/maintainability)
5
+ [![Test Coverage](https://api.codeclimate.com/v1/badges/c22da1693543a6eac7e9/test_coverage)](https://codeclimate.com/github/rootstrap/rsgem/test_coverage)
6
+
7
+ `rsgem` is a tool to help you start developing gems with the defaults we use at Rootstrap.
8
+
9
+ ## Installation
10
+
11
+ $ gem install rsgem
12
+
13
+ We highly suggest to not include `rsgem` in your Gemfile.
14
+ `rsgem` is not a library, and should not affect the dependency tree of your application.
15
+
16
+ ## Usage
17
+
18
+ ```
19
+ rsgem new NAME [CI_PROVIDER]
20
+ ```
21
+
22
+ RSGem will solve the following tasks for you:
23
+
24
+ 1. Create a folder for your gem leveraging bundler's defaults. (You need bundler in your system)
25
+ 1. Add the following dependencies:
26
+ - [Rake](https://github.com/ruby/rake)
27
+ - [Reek](https://github.com/troessner/reek)
28
+ - [RSpec](https://github.com/rspec/rspec)
29
+ - [Rubocop](https://github.com/rubocop-hq/rubocop)
30
+ - [Simplecov](https://github.com/colszowka/simplecov)
31
+ - We use Simplecov at 0.17.1 because that's the latest compatible version with CodeClimate.
32
+ 1. Add configuration files for Reek and Rubocop with default Rootstrap's configuration.
33
+ 1. Add a rake task to run Rubocop and Reek by calling `rake code_analysis`.
34
+ 1. [Clean the Gemfile](https://github.com/rootstrap/tech-guides/blob/master/open-source/developing_gems.md#gemfilegemfilelockgemspec).
35
+ 1. [Git ignore the Gemfile.lock](https://github.com/rootstrap/tech-guides/blob/master/open-source/developing_gems.md#gemfilegemfilelockgemspec)
36
+ 1. Add a CI provider configuration. GitHub Actions and Travis are available providers. Travis is the default.
37
+ 1. Set the bundled files to be a short list of files. By default the gem will bundle:
38
+ - LICENSE.txt
39
+ - README.md
40
+ - lib/**/* (everything inside lib)
41
+ 1. Apply Rubocop style fixes
42
+
43
+ #### Examples
44
+
45
+ ```
46
+ rsgem new foo
47
+ ```
48
+ Creates a new gem called foo.
49
+
50
+ ```
51
+ rsgem new bar github_actions
52
+ ```
53
+ Creates a new gem called bar that uses Github Actions as the CI provider.
54
+
55
+ #### Help
56
+
57
+ ```
58
+ rsgem -h
59
+ ```
60
+ Displays global help.
61
+
62
+ ```
63
+ rsgem new -h
64
+ ```
65
+ Displays help for the `new` command.
66
+
67
+ ## Development
68
+
69
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bundle exec rspec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
70
+
71
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
72
+
73
+ ## Contributing
74
+
75
+ Bug reports and pull requests are welcome on GitHub at https://github.com/rootstrap/rsgem. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/rootstrap/rsgem/blob/master/CODE_OF_CONDUCT.md).
76
+
77
+
78
+ ## License
79
+
80
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
81
+
82
+ ## Code of Conduct
83
+
84
+ Everyone interacting in the Rootstrap project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/rootstrap/rsgem/blob/master/CODE_OF_CONDUCT.md).
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'rsgem'
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require 'irb'
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/exe/rsgem ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'rsgem'
6
+
7
+ Dry::CLI.new(RSGem::CLI::Commands).call
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RSGem
4
+ module CIProviders
5
+ class Base
6
+ attr_reader :config_file_destination, :config_file_source, :name, :display_name
7
+
8
+ def initialize(config_file_source: nil, config_file_destination: nil, display_name:, name:)
9
+ @config_file_source = config_file_source
10
+ @config_file_destination = config_file_destination
11
+ @display_name = display_name
12
+ @name = name
13
+ end
14
+
15
+ def install(context)
16
+ destination = "#{context.folder_path}/#{config_file_destination}"
17
+
18
+ File.delete(destination) if File.exist?(destination)
19
+ FileUtils.mkdir_p(File.dirname(destination))
20
+ File.open(destination, 'w') do |file|
21
+ file.puts config_file_source_content
22
+ end
23
+
24
+ puts "\t#{display_name} CI configuration added"
25
+ end
26
+
27
+ private
28
+
29
+ def config_file_source_content
30
+ File.read(config_file_source)
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RSGem
4
+ module CIProviders
5
+ GithubActions = Base.new(
6
+ config_file_source: "#{File.dirname(__FILE__)}/../support/github_actions.yml",
7
+ config_file_destination: '.github/workflows/ci.yml',
8
+ display_name: 'Github Actions',
9
+ name: 'github_actions'
10
+ )
11
+ end
12
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RSGem
4
+ module CIProviders
5
+ Travis = Base.new(config_file_source: "#{File.dirname(__FILE__)}/../support/travis.yml",
6
+ config_file_destination: '.travis.yml',
7
+ display_name: 'Travis',
8
+ name: 'travis')
9
+ end
10
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RSGem
4
+ module CLI
5
+ module Commands
6
+ class New < Dry::CLI::Command
7
+ def self.ci_provider_options
8
+ RSGem::Constants::CI_PROVIDERS.map { |ci| "'#{ci.name}'" }.join(', ')
9
+ end
10
+
11
+ desc 'Create a new gem'
12
+
13
+ argument :gem_name, type: :string, required: true, desc: 'Name of your new gem'
14
+ argument :ci_provider, type: :string, required: false,
15
+ desc: 'CI provider to use. '\
16
+ "Available options are: #{ci_provider_options}. "\
17
+ "Default option is 'travis'"
18
+
19
+ example [
20
+ 'foo # Creates a new gem called foo',
21
+ 'bar github_actions # Creates a new gem called bar, with GitHub Actions as the '\
22
+ 'CI provider'
23
+ ]
24
+
25
+ def call(**options)
26
+ RSGem::Gem.new(gem_name: options[:gem_name], ci_provider: options[:ci_provider]).create
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RSGem
4
+ module CLI
5
+ module Commands
6
+ class Version < Dry::CLI::Command
7
+ desc 'Print version'
8
+
9
+ def call(*)
10
+ puts RSGem::VERSION
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RSGem
4
+ module CLI
5
+ module Commands
6
+ extend Dry::CLI::Registry
7
+
8
+ register 'new', New
9
+ register 'version', Version, aliases: ['v', '-v', '--version']
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RSGem
4
+ module Constants
5
+ CI_PROVIDERS = [
6
+ RSGem::CIProviders::GithubActions,
7
+ RSGem::CIProviders::Travis
8
+ ].freeze
9
+ DEFAULT_CI_PROVIDER = RSGem::CIProviders::Travis
10
+ end
11
+ end
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RSGem
4
+ class Context
5
+ attr_reader :options
6
+
7
+ def initialize(options:)
8
+ @options = options
9
+
10
+ raise MissingGemNameError unless options[:gem_name]
11
+ end
12
+
13
+ def ci_provider
14
+ @ci_provider ||= begin
15
+ return RSGem::Constants::DEFAULT_CI_PROVIDER unless (name = options[:ci_provider])
16
+
17
+ RSGem::Constants::CI_PROVIDERS.detect do |provider|
18
+ provider.name == name
19
+ end
20
+ end
21
+ end
22
+
23
+ def gemfile_path
24
+ "#{folder_path}/Gemfile"
25
+ end
26
+
27
+ def gem_name
28
+ @gem_name ||= options[:gem_name]
29
+ end
30
+
31
+ def gemspec_path
32
+ "#{folder_path}/#{gem_name}.gemspec"
33
+ end
34
+
35
+ def folder_path
36
+ `pwd`.sub("\n", '/') + gem_name
37
+ end
38
+
39
+ def gitignore_path
40
+ "#{folder_path}/.gitignore"
41
+ end
42
+
43
+ def rakefile_path
44
+ "#{folder_path}/Rakefile"
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RSGem
4
+ module Dependencies
5
+ class Base
6
+ attr_reader :config_file_destination, :config_file_source, :mode, :name, :version
7
+
8
+ def initialize(config_file_source: nil, config_file_destination: nil, mode: :development,
9
+ name:, version: nil)
10
+ @config_file_source = config_file_source
11
+ @config_file_destination = config_file_destination
12
+ @mode = mode # Either `development' or `runtime'
13
+ @name = name
14
+ @version = version ? "'#{version}'" : nil
15
+ end
16
+
17
+ def install(context)
18
+ if config_file_source
19
+ File.open("#{context.folder_path}/#{config_file_destination}", 'w') do |file|
20
+ file.puts config_file_source_content
21
+ end
22
+ end
23
+
24
+ puts "\t#{name.capitalize} installed"
25
+ end
26
+
27
+ private
28
+
29
+ def config_file_source_content
30
+ File.read(config_file_source)
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RSGem
4
+ module Dependencies
5
+ Rake = Base.new(name: 'rake')
6
+ end
7
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RSGem
4
+ module Dependencies
5
+ Reek = Base.new(
6
+ config_file_source: "#{File.dirname(__FILE__)}/../support/reek.yml",
7
+ config_file_destination: '.reek.yml',
8
+ name: 'reek'
9
+ )
10
+ end
11
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RSGem
4
+ module Dependencies
5
+ RSpec = Base.new(name: 'rspec')
6
+ end
7
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RSGem
4
+ module Dependencies
5
+ Rubocop = Base.new(
6
+ config_file_source: "#{File.dirname(__FILE__)}/../support/rubocop.yml",
7
+ config_file_destination: '.rubocop.yml',
8
+ name: 'rubocop'
9
+ )
10
+ end
11
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RSGem
4
+ module Dependencies
5
+ # This is the latest stable version working correctly with codeclimate
6
+ # 0.18+ does not work currently https://github.com/codeclimate/test-reporter/issues/413
7
+ Simplecov = Base.new(name: 'simplecov', version: '~> 0.17.1')
8
+ end
9
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RSGem
4
+ class MissingGemNameError < StandardError
5
+ end
6
+ end
data/lib/rsgem/gem.rb ADDED
@@ -0,0 +1,70 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RSGem
4
+ class Gem
5
+ attr_reader :options
6
+
7
+ def initialize(options)
8
+ @options = options
9
+ end
10
+
11
+ def create
12
+ `bundle gem #{context.gem_name}`
13
+
14
+ add_code_analysis
15
+ add_dependencies
16
+ clean_gemfile
17
+ ignore_gemfile_lock
18
+ add_ci_provider
19
+ clean_gemspec
20
+ set_bundled_files
21
+ run_rubocop
22
+ end
23
+
24
+ private
25
+
26
+ def add_ci_provider
27
+ context.ci_provider.install(context)
28
+ end
29
+
30
+ def add_code_analysis
31
+ Tasks::AddCodeAnalysis.new(context: context).add
32
+ end
33
+
34
+ def add_dependencies
35
+ [
36
+ Dependencies::Rake,
37
+ Dependencies::Reek,
38
+ Dependencies::RSpec,
39
+ Dependencies::Rubocop,
40
+ Dependencies::Simplecov
41
+ ].each do |dependency|
42
+ Tasks::AddDependency.new(context: context, dependency: dependency).add
43
+ end
44
+ end
45
+
46
+ def clean_gemfile
47
+ Tasks::CleanGemfile.new(context: context).clean
48
+ end
49
+
50
+ def clean_gemspec
51
+ Tasks::CleanGemspec.new(context: context).clean
52
+ end
53
+
54
+ def context
55
+ @context ||= Context.new(options: options)
56
+ end
57
+
58
+ def ignore_gemfile_lock
59
+ Tasks::IgnoreGemfileLock.new(context: context).ignore
60
+ end
61
+
62
+ def run_rubocop
63
+ Tasks::RunRubocop.new(context: context).run
64
+ end
65
+
66
+ def set_bundled_files
67
+ Tasks::SetBundledFiles.new(context: context).set
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ task :code_analysis do
4
+ sh 'bundle exec rubocop lib spec'
5
+ sh 'bundle exec reek lib'
6
+ end
@@ -0,0 +1,36 @@
1
+ name: ci
2
+
3
+ on: push
4
+
5
+ jobs:
6
+ build:
7
+ runs-on: ubuntu-latest
8
+ strategy:
9
+ matrix:
10
+ ruby_version: [2.5.x, 2.6.x, 2.7.x]
11
+
12
+ steps:
13
+ - uses: actions/checkout@v2
14
+ - name: Set up Ruby
15
+ uses: actions/setup-ruby@v1
16
+ with:
17
+ ruby-version: ${{ matrix.ruby_version }}
18
+ - name: Download CodeClimate reporter
19
+ run: |
20
+ curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
21
+ chmod +x ./cc-test-reporter
22
+ ./cc-test-reporter before-build
23
+ env:
24
+ CC_TEST_REPORTER_ID: get_a_test_reporter_id_from_code_climate
25
+ - name: Build and test
26
+ run: |
27
+ gem install bundler:1.17.3
28
+ bundle update
29
+ bundle install --jobs 4 --retry 3
30
+ bundle exec rake code_analysis
31
+ bundle exec rspec
32
+ - name: Report to CodeClimate
33
+ run: |
34
+ ./cc-test-reporter after-build --exit-code 0
35
+ env:
36
+ CC_TEST_REPORTER_ID: get_a_test_reporter_id_from_code_climate
@@ -0,0 +1,127 @@
1
+ detectors:
2
+ Attribute:
3
+ enabled: false
4
+ exclude: []
5
+ BooleanParameter:
6
+ enabled: true
7
+ exclude: []
8
+ ClassVariable:
9
+ enabled: false
10
+ exclude: []
11
+ ControlParameter:
12
+ enabled: true
13
+ exclude: []
14
+ DataClump:
15
+ enabled: true
16
+ exclude: []
17
+ max_copies: 2
18
+ min_clump_size: 2
19
+ DuplicateMethodCall:
20
+ enabled: true
21
+ exclude: []
22
+ max_calls: 1
23
+ allow_calls: []
24
+ FeatureEnvy:
25
+ enabled: true
26
+ exclude: []
27
+ InstanceVariableAssumption:
28
+ enabled: false
29
+ IrresponsibleModule:
30
+ enabled: false
31
+ exclude: []
32
+ LongParameterList:
33
+ enabled: true
34
+ exclude: []
35
+ max_params: 4
36
+ overrides:
37
+ initialize:
38
+ max_params: 5
39
+ LongYieldList:
40
+ enabled: true
41
+ exclude: []
42
+ max_params: 3
43
+ ManualDispatch:
44
+ enabled: true
45
+ exclude: []
46
+ MissingSafeMethod:
47
+ enabled: false
48
+ exclude: []
49
+ ModuleInitialize:
50
+ enabled: true
51
+ exclude: []
52
+ NestedIterators:
53
+ enabled: true
54
+ exclude: []
55
+ max_allowed_nesting: 2
56
+ ignore_iterators: []
57
+ NilCheck:
58
+ enabled: false
59
+ exclude: []
60
+ RepeatedConditional:
61
+ enabled: true
62
+ exclude: []
63
+ max_ifs: 3
64
+ SubclassedFromCoreClass:
65
+ enabled: true
66
+ exclude: []
67
+ TooManyConstants:
68
+ enabled: true
69
+ exclude: []
70
+ max_constants: 5
71
+ TooManyInstanceVariables:
72
+ enabled: true
73
+ exclude: []
74
+ max_instance_variables: 9
75
+ TooManyMethods:
76
+ enabled: true
77
+ exclude: []
78
+ max_methods: 25
79
+ TooManyStatements:
80
+ enabled: true
81
+ exclude:
82
+ - initialize
83
+ max_statements: 12
84
+ UncommunicativeMethodName:
85
+ enabled: true
86
+ exclude: []
87
+ reject:
88
+ - "/^[a-z]$/"
89
+ - "/[0-9]$/"
90
+ - "/[A-Z]/"
91
+ accept: []
92
+ UncommunicativeModuleName:
93
+ enabled: true
94
+ exclude: []
95
+ reject:
96
+ - "/^.$/"
97
+ - "/[0-9]$/"
98
+ accept:
99
+ - Inline::C
100
+ - "/V[0-9]/"
101
+ UncommunicativeParameterName:
102
+ enabled: true
103
+ exclude: []
104
+ reject:
105
+ - "/^.$/"
106
+ - "/[0-9]$/"
107
+ - "/[A-Z]/"
108
+ accept: []
109
+ UncommunicativeVariableName:
110
+ enabled: true
111
+ exclude: []
112
+ reject:
113
+ - "/^.$/"
114
+ - "/[0-9]$/"
115
+ - "/[A-Z]/"
116
+ accept:
117
+ - _
118
+ UnusedParameters:
119
+ enabled: true
120
+ exclude: []
121
+ UnusedPrivateMethod:
122
+ enabled: false
123
+ UtilityFunction:
124
+ enabled: false
125
+
126
+ exclude_paths:
127
+ - config
@@ -0,0 +1,81 @@
1
+ Style/Documentation:
2
+ Enabled: false
3
+
4
+ Layout/SpaceBeforeFirstArg:
5
+ Exclude:
6
+
7
+ Lint/AmbiguousBlockAssociation:
8
+ Exclude:
9
+ - spec/**/*
10
+
11
+ Metrics/AbcSize:
12
+ # The ABC size is a calculated magnitude, so this number can be an Integer or
13
+ # a Float.
14
+ Max: 15
15
+
16
+ Metrics/BlockLength:
17
+ CountComments: false
18
+ Max: 25
19
+ Exclude:
20
+ - '*.gemspec'
21
+ - config/**/*
22
+ - spec/**/*
23
+ ExcludedMethods:
24
+ - class_methods
25
+
26
+ Metrics/BlockNesting:
27
+ Max: 4
28
+
29
+ Metrics/ClassLength:
30
+ CountComments: false
31
+ Max: 200
32
+
33
+ # Avoid complex methods.
34
+ Metrics/CyclomaticComplexity:
35
+ Max: 7
36
+
37
+ Metrics/MethodLength:
38
+ CountComments: false
39
+ Max: 24
40
+
41
+ Metrics/ModuleLength:
42
+ CountComments: false
43
+ Max: 200
44
+
45
+ Layout/LineLength:
46
+ Max: 100
47
+ # To make it possible to copy or click on URIs in the code, we allow lines
48
+ # containing a URI to be longer than Max.
49
+ AllowURI: true
50
+ URISchemes:
51
+ - http
52
+ - https
53
+
54
+ Metrics/ParameterLists:
55
+ Max: 5
56
+ CountKeywordArgs: true
57
+
58
+ Metrics/PerceivedComplexity:
59
+ Max: 12
60
+
61
+ Style/FrozenStringLiteralComment:
62
+ Enabled: true
63
+
64
+ Style/ModuleFunction:
65
+ Enabled: false
66
+
67
+ Style/RescueModifier:
68
+ Exclude:
69
+ - spec/**/*
70
+
71
+ Naming/PredicateName:
72
+ Enabled: false
73
+
74
+ Style/HashEachMethods:
75
+ Enabled: true
76
+
77
+ Style/HashTransformKeys:
78
+ Enabled: true
79
+
80
+ Style/HashTransformValues:
81
+ Enabled: true
@@ -0,0 +1,28 @@
1
+ language: ruby
2
+
3
+ rvm:
4
+ - 2.5.0
5
+ - 2.6.0
6
+ - ruby-head
7
+
8
+ dist: bionic
9
+
10
+ jobs:
11
+ allow_failures:
12
+ - rvm: ruby-head
13
+
14
+ env:
15
+ global:
16
+ - CC_TEST_REPORTER_ID=get_a_test_reporter_id_from_code_climate
17
+
18
+ before_script:
19
+ - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
20
+ - chmod +x ./cc-test-reporter
21
+ - ./cc-test-reporter before-build
22
+
23
+ script:
24
+ - bundle exec rake code_analysis
25
+ - bundle exec rspec
26
+
27
+ after_script:
28
+ - ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RSGem
4
+ module Tasks
5
+ class AddCodeAnalysis
6
+ attr_reader :context
7
+
8
+ def initialize(context:)
9
+ @context = context
10
+ end
11
+
12
+ def add
13
+ File.open(context.rakefile_path, 'w') do |file|
14
+ file.puts rakefile
15
+ end
16
+ end
17
+
18
+ private
19
+
20
+ def rakefile
21
+ @rakefile ||= File.read("#{File.dirname(__FILE__)}/../support/Rakefile")
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RSGem
4
+ module Tasks
5
+ class AddDependency
6
+ attr_reader :context, :dependency
7
+
8
+ def initialize(context:, dependency:)
9
+ @context = context
10
+ @dependency = dependency
11
+ end
12
+
13
+ def add
14
+ return if already_installed?
15
+
16
+ add_dependency
17
+ write_to_gemspec
18
+ dependency.install(context)
19
+ end
20
+
21
+ private
22
+
23
+ def add_dependency
24
+ gemspec_file.gsub!(/end\n\z/, code)
25
+ gemspec_file << "\nend"
26
+ end
27
+
28
+ def already_installed?
29
+ gemspec_file.match? Regexp.new("('|\")#{dependency.name}('|\")")
30
+ end
31
+
32
+ def code
33
+ text = [" spec.add_#{dependency.mode}_dependency '#{dependency.name}'", dependency.version]
34
+ text.compact.join(', ')
35
+ end
36
+
37
+ def gemspec_file
38
+ @gemspec_file ||= File.read(context.gemspec_path)
39
+ end
40
+
41
+ def write_to_gemspec
42
+ File.open(context.gemspec_path, 'w') do |file|
43
+ file.puts gemspec_file
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RSGem
4
+ module Tasks
5
+ #
6
+ # Gemfile should only have the gemspec directive.
7
+ # An exception is when you need to develop against a gem that hasn't yet been released,
8
+ # in this case you can declare that dependency in the Gemfile:
9
+ #
10
+ # gem 'rack', github: 'rack/rack'
11
+ #
12
+ # gemspec is the place to declare dependencies.
13
+ #
14
+ # https://github.com/rootstrap/tech-guides/blob/master/open-source/developing_gems.md#gemfilegemfilelockgemspec
15
+ #
16
+ class CleanGemfile
17
+ attr_reader :context
18
+
19
+ def initialize(context:)
20
+ @context = context
21
+ end
22
+
23
+ def clean
24
+ gemfile.gsub!(/gem .+\n/, '') # Remove all gem definitions
25
+ gemfile.sub!(/\n\z/, '') # Remove last new line character
26
+ write_to_gemfile
27
+ puts "\tGemfile cleaned"
28
+ end
29
+
30
+ private
31
+
32
+ def gemfile
33
+ @gemfile ||= File.read(context.gemfile_path)
34
+ end
35
+
36
+ def write_to_gemfile
37
+ File.open(context.gemfile_path, 'w') do |file|
38
+ file.puts gemfile
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RSGem
4
+ module Tasks
5
+ class CleanGemspec
6
+ attr_reader :context
7
+
8
+ KEYS_TO_EMPTY = %w[summary description homepage].freeze
9
+
10
+ def initialize(context:)
11
+ @context = context
12
+ end
13
+
14
+ def clean
15
+ comment_metadata!
16
+ empty_keys!
17
+ write
18
+ end
19
+
20
+ private
21
+
22
+ def gemspec
23
+ @gemspec ||= File.read(context.gemspec_path)
24
+ end
25
+
26
+ def empty_keys!
27
+ KEYS_TO_EMPTY.each do |key|
28
+ gemspec.gsub!(/(spec.#{key}.*)=(.*)\n/, "\\1= ''\n")
29
+ end
30
+ end
31
+
32
+ def comment_metadata!
33
+ gemspec.gsub!(/spec.metadata/, '# spec.metadata')
34
+ end
35
+
36
+ def write
37
+ File.open(context.gemspec_path, 'w') do |file|
38
+ file.puts gemspec
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RSGem
4
+ module Tasks
5
+ #
6
+ # Gemfile.lock should be gitignored when developing gems
7
+ #
8
+ # https://github.com/rootstrap/tech-guides/blob/master/open-source/developing_gems.md#gemfilegemfilelockgemspec
9
+ #
10
+ class IgnoreGemfileLock
11
+ attr_reader :context
12
+
13
+ def initialize(context:)
14
+ @context = context
15
+ end
16
+
17
+ def ignore
18
+ gitignore << "\nGemfile.lock\n"
19
+ write_to_gitignore
20
+ puts "\tGemfile.lock added to .gitignore"
21
+ end
22
+
23
+ private
24
+
25
+ def gitignore
26
+ @gitignore ||= File.read(context.gitignore_path)
27
+ end
28
+
29
+ def write_to_gitignore
30
+ File.open(context.gitignore_path, 'w') do |file|
31
+ file.puts gitignore
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RSGem
4
+ module Tasks
5
+ class RunRubocop
6
+ attr_reader :context, :output
7
+
8
+ def initialize(context:)
9
+ @context = context
10
+ end
11
+
12
+ def run
13
+ puts "\tRubocop:"
14
+ @output = `cd #{context.folder_path} && bundle exec rubocop -a`
15
+ puts "\t\t#{last_line}"
16
+ end
17
+
18
+ private
19
+
20
+ def last_line
21
+ @output.split("\n").last
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RSGem
4
+ module Tasks
5
+ #
6
+ # When the gem is bundled into final users' projects, it only needs to contain the production
7
+ # code. Meaning that specs, docs, configuration files should not be present.
8
+ # This task updates the default `spec.files` configuration in the gemspec to just contain the
9
+ # files:
10
+ # - LICENSE.txt
11
+ # - README.md
12
+ # - lib/**/* (everything inside lib)
13
+ #
14
+ class SetBundledFiles
15
+ attr_reader :context
16
+
17
+ def initialize(context:)
18
+ @context = context
19
+ end
20
+
21
+ def set
22
+ # Explaining the regular expression:
23
+ # [spec.files][one or more white spaces][=][one or more white spaces][anything until "do"]
24
+ # [new line][anything until new line]
25
+ # [one or more white spaces][end]
26
+ gemspec.gsub!(
27
+ /spec.files\s+=\s+.+do\n.+\n\s+end/,
28
+ "spec.files = Dir['LICENSE.txt', 'README.md', 'lib/**/*']"
29
+ )
30
+ write
31
+
32
+ puts "\tGemspec files config updated"
33
+ end
34
+
35
+ private
36
+
37
+ def gemspec
38
+ @gemspec ||= File.read(context.gemspec_path)
39
+ end
40
+
41
+ def write
42
+ File.open(context.gemspec_path, 'w') do |file|
43
+ file.puts gemspec
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RSGem
4
+ MAJOR = 0
5
+ MINOR = 1
6
+ PATCH = 0
7
+ VERSION = [MAJOR, MINOR, PATCH].join('.')
8
+ end
data/lib/rsgem.rb ADDED
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rsgem/version'
4
+ require 'rsgem/gem'
5
+ require 'rsgem/errors/missing_gem_name_error'
6
+ require 'rsgem/ci_providers/base'
7
+ require 'rsgem/ci_providers/github_actions'
8
+ require 'rsgem/ci_providers/travis'
9
+ require 'rsgem/tasks/add_code_analysis'
10
+ require 'rsgem/tasks/add_dependency'
11
+ require 'rsgem/tasks/clean_gemfile'
12
+ require 'rsgem/tasks/ignore_gemfile_lock'
13
+ require 'rsgem/tasks/clean_gemspec'
14
+ require 'rsgem/tasks/run_rubocop'
15
+ require 'rsgem/tasks/set_bundled_files'
16
+ require 'rsgem/dependencies/base'
17
+ require 'rsgem/dependencies/rake'
18
+ require 'rsgem/dependencies/reek'
19
+ require 'rsgem/dependencies/rspec'
20
+ require 'rsgem/dependencies/rubocop'
21
+ require 'rsgem/dependencies/simplecov'
22
+ require 'rsgem/constants'
23
+ require 'rsgem/context'
24
+ require 'dry/cli'
25
+ require 'rsgem/cli/commands/new'
26
+ require 'rsgem/cli/commands/version'
27
+ require 'rsgem/cli/commands'
28
+
29
+ module RSGem
30
+ end
metadata ADDED
@@ -0,0 +1,179 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rsgem
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Juan Manuel Ramallo
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-04-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: dry-cli
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.6.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.6.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: pry
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.13.0
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.13.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 13.0.1
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 13.0.1
55
+ - !ruby/object:Gem::Dependency
56
+ name: reek
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 5.6.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 5.6.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 3.9.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 3.9.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 0.80.0
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 0.80.0
97
+ - !ruby/object:Gem::Dependency
98
+ name: simplecov
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 0.17.1
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 0.17.1
111
+ description:
112
+ email:
113
+ - ramallojuanm@gmail.com
114
+ executables:
115
+ - rsgem
116
+ extensions: []
117
+ extra_rdoc_files: []
118
+ files:
119
+ - LICENSE.txt
120
+ - README.md
121
+ - bin/console
122
+ - bin/setup
123
+ - exe/rsgem
124
+ - lib/rsgem.rb
125
+ - lib/rsgem/ci_providers/base.rb
126
+ - lib/rsgem/ci_providers/github_actions.rb
127
+ - lib/rsgem/ci_providers/travis.rb
128
+ - lib/rsgem/cli/commands.rb
129
+ - lib/rsgem/cli/commands/new.rb
130
+ - lib/rsgem/cli/commands/version.rb
131
+ - lib/rsgem/constants.rb
132
+ - lib/rsgem/context.rb
133
+ - lib/rsgem/dependencies/base.rb
134
+ - lib/rsgem/dependencies/rake.rb
135
+ - lib/rsgem/dependencies/reek.rb
136
+ - lib/rsgem/dependencies/rspec.rb
137
+ - lib/rsgem/dependencies/rubocop.rb
138
+ - lib/rsgem/dependencies/simplecov.rb
139
+ - lib/rsgem/errors/missing_gem_name_error.rb
140
+ - lib/rsgem/gem.rb
141
+ - lib/rsgem/support/Rakefile
142
+ - lib/rsgem/support/github_actions.yml
143
+ - lib/rsgem/support/reek.yml
144
+ - lib/rsgem/support/rubocop.yml
145
+ - lib/rsgem/support/travis.yml
146
+ - lib/rsgem/tasks/add_code_analysis.rb
147
+ - lib/rsgem/tasks/add_dependency.rb
148
+ - lib/rsgem/tasks/clean_gemfile.rb
149
+ - lib/rsgem/tasks/clean_gemspec.rb
150
+ - lib/rsgem/tasks/ignore_gemfile_lock.rb
151
+ - lib/rsgem/tasks/run_rubocop.rb
152
+ - lib/rsgem/tasks/set_bundled_files.rb
153
+ - lib/rsgem/version.rb
154
+ homepage: https://github.com/rootstrap/rsgem
155
+ licenses:
156
+ - MIT
157
+ metadata:
158
+ homepage_uri: https://github.com/rootstrap/rsgem
159
+ source_code_uri: https://github.com/rootstrap/rsgem
160
+ post_install_message:
161
+ rdoc_options: []
162
+ require_paths:
163
+ - lib
164
+ required_ruby_version: !ruby/object:Gem::Requirement
165
+ requirements:
166
+ - - ">="
167
+ - !ruby/object:Gem::Version
168
+ version: 2.3.0
169
+ required_rubygems_version: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ requirements: []
175
+ rubygems_version: 3.1.2
176
+ signing_key:
177
+ specification_version: 4
178
+ summary: Generating gems the Rootstrap way
179
+ test_files: []