rsgem 0.1.3 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: deec5cd29ecd1189ee350da6c7d15bdf197c21f0670e5158251cb214b0fb98b4
4
- data.tar.gz: 28758518b1a52a52dca2945a136c23ee851e45c9a63ca599b6090c232e6680b6
3
+ metadata.gz: 118dc51b1e8cef7481205fc789643bbb5e90e033eb84a20f18b20df73bca1efc
4
+ data.tar.gz: bc24898da5bd9b1047a67d24349e72aa6e7432aa15f040c2981e42790376991b
5
5
  SHA512:
6
- metadata.gz: e646ac023ad600bb4c0556034ba7249d6ca271ba50aecd8d4a0c6eff029095f06250ecd4e742f8d353b2d370af163893a0aac16659a22f115d9eb80c34238ff9
7
- data.tar.gz: 044134b37c4cfca91e21633218f19f299e481b7008b582e412c31fd24e7f358e65b49f12cbefb3bc8d55ca74e130ac013eab339a1ff218782777927b8e0fe9e9
6
+ metadata.gz: d280d17fb9f125345d21e4ebb1d1fbfc445ca69b063fff66c2c80a00c0c89767fe3b5afeec2f025b92a0136e7ab3df7642133d0abf6db692f8b6148a2824bbee
7
+ data.tar.gz: a90e71674a3613857b19867b79787ffdc41783103a517a776be9ec4a35ac159e19bbc8f2a81d50acd2ba91f325a4b69032ee9b8459e80c442f532765c46e8d1b
@@ -1,5 +1,13 @@
1
1
  # master
2
2
 
3
+ # 0.2.0
4
+
5
+ * Add default configuration for simplecov in spec_helper.rb
6
+
7
+ * Display an error message if bundler failed to run or is not present in the system
8
+
9
+ *Juan Manuel Ramallo*
10
+
3
11
  # 0.1.3
4
12
 
5
13
  * Fix gem creation task on Linux
@@ -6,6 +6,7 @@ require 'rsgem/errors/missing_gem_name_error'
6
6
  require 'rsgem/ci_providers/base'
7
7
  require 'rsgem/ci_providers/github_actions'
8
8
  require 'rsgem/ci_providers/travis'
9
+ require 'rsgem/tasks/base'
9
10
  require 'rsgem/tasks/add_code_analysis'
10
11
  require 'rsgem/tasks/add_dependency'
11
12
  require 'rsgem/tasks/clean_gemfile'
@@ -15,6 +16,7 @@ require 'rsgem/tasks/clean_gemspec'
15
16
  require 'rsgem/tasks/bundle_dependencies'
16
17
  require 'rsgem/tasks/run_rubocop'
17
18
  require 'rsgem/tasks/set_bundled_files'
19
+ require 'rsgem/tasks/simple_cov_post_install'
18
20
  require 'rsgem/dependencies/base'
19
21
  require 'rsgem/dependencies/rake'
20
22
  require 'rsgem/dependencies/reek'
@@ -47,5 +47,9 @@ module RSGem
47
47
  def rakefile_path
48
48
  "#{folder_path}/Rakefile"
49
49
  end
50
+
51
+ def spec_helper_path
52
+ "#{folder_path}/spec/spec_helper.rb"
53
+ end
50
54
  end
51
55
  end
@@ -3,14 +3,16 @@
3
3
  module RSGem
4
4
  module Dependencies
5
5
  class Base
6
- attr_reader :config_file_destination, :config_file_source, :mode, :name, :version
6
+ attr_reader :config_file_destination, :config_file_source, :mode, :name, :post_install_task,
7
+ :version
7
8
 
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'
9
+ def initialize(name:, **args)
10
+ @config_file_source = args[:config_file_source]
11
+ @config_file_destination = args[:config_file_destination]
12
+ @mode = args[:mode] || 'development' # Either `development' or `runtime'
13
13
  @name = name
14
+ @post_install_task = args[:post_install_task]
15
+ version = args[:version]
14
16
  @version = version ? "'#{version}'" : nil
15
17
  end
16
18
 
@@ -21,6 +23,8 @@ module RSGem
21
23
  end
22
24
  end
23
25
 
26
+ post_install_task&.new(context: context)&.perform
27
+
24
28
  puts "\t#{name.capitalize} installed"
25
29
  end
26
30
 
@@ -4,6 +4,7 @@ module RSGem
4
4
  module Dependencies
5
5
  # This is the latest stable version working correctly with codeclimate
6
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')
7
+ Simplecov = Base.new(name: 'simplecov', version: '~> 0.17.1',
8
+ post_install_task: RSGem::Tasks::SimpleCovPostInstall)
8
9
  end
9
10
  end
@@ -28,7 +28,7 @@ module RSGem
28
28
  end
29
29
 
30
30
  def add_code_analysis
31
- Tasks::AddCodeAnalysis.new(context: context).add
31
+ Tasks::AddCodeAnalysis.new(context: context).perform
32
32
  end
33
33
 
34
34
  def add_dependencies
@@ -39,16 +39,16 @@ module RSGem
39
39
  Dependencies::Rubocop,
40
40
  Dependencies::Simplecov
41
41
  ].each do |dependency|
42
- Tasks::AddDependency.new(context: context, dependency: dependency).add
42
+ Tasks::AddDependency.new(context: context, dependency: dependency).perform
43
43
  end
44
44
  end
45
45
 
46
46
  def clean_gemfile
47
- Tasks::CleanGemfile.new(context: context).clean
47
+ Tasks::CleanGemfile.new(context: context).perform
48
48
  end
49
49
 
50
50
  def clean_gemspec
51
- Tasks::CleanGemspec.new(context: context).clean
51
+ Tasks::CleanGemspec.new(context: context).perform
52
52
  end
53
53
 
54
54
  def context
@@ -56,23 +56,23 @@ module RSGem
56
56
  end
57
57
 
58
58
  def create_gem
59
- Tasks::CreateGem.new(context: context).create
59
+ Tasks::CreateGem.new(context: context).perform
60
60
  end
61
61
 
62
62
  def ignore_gemfile_lock
63
- Tasks::IgnoreGemfileLock.new(context: context).ignore
63
+ Tasks::IgnoreGemfileLock.new(context: context).perform
64
64
  end
65
65
 
66
66
  def run_rubocop
67
- Tasks::RunRubocop.new(context: context).run
67
+ Tasks::RunRubocop.new(context: context).perform
68
68
  end
69
69
 
70
70
  def bundle_dependencies
71
- Tasks::BundleDependencies.new(context: context).run
71
+ Tasks::BundleDependencies.new(context: context).perform
72
72
  end
73
73
 
74
74
  def set_bundled_files
75
- Tasks::SetBundledFiles.new(context: context).set
75
+ Tasks::SetBundledFiles.new(context: context).perform
76
76
  end
77
77
  end
78
78
  end
@@ -2,14 +2,8 @@
2
2
 
3
3
  module RSGem
4
4
  module Tasks
5
- class AddCodeAnalysis
6
- attr_reader :context
7
-
8
- def initialize(context:)
9
- @context = context
10
- end
11
-
12
- def add
5
+ class AddCodeAnalysis < Base
6
+ def perform
13
7
  File.open(context.rakefile_path, 'w') do |file|
14
8
  file.puts rakefile
15
9
  end
@@ -2,15 +2,8 @@
2
2
 
3
3
  module RSGem
4
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
5
+ class AddDependency < Base
6
+ def perform
14
7
  return if already_installed?
15
8
 
16
9
  add_dependency
@@ -34,6 +27,10 @@ module RSGem
34
27
  text.compact.join(', ')
35
28
  end
36
29
 
30
+ def dependency
31
+ args[:dependency]
32
+ end
33
+
37
34
  def gemspec_file
38
35
  @gemspec_file ||= File.read(context.gemspec_path)
39
36
  end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RSGem
4
+ module Tasks
5
+ #
6
+ # Base class for task objects.
7
+ # Child classes must implement the instance method +perform+.
8
+ #
9
+ class Base
10
+ attr_reader :context, :args
11
+
12
+ def initialize(context:, **args)
13
+ @context = context
14
+ @args = args
15
+ end
16
+ end
17
+ end
18
+ end
@@ -2,14 +2,8 @@
2
2
 
3
3
  module RSGem
4
4
  module Tasks
5
- class BundleDependencies
6
- attr_reader :context, :output
7
-
8
- def initialize(context:)
9
- @context = context
10
- end
11
-
12
- def run
5
+ class BundleDependencies < Base
6
+ def perform
13
7
  puts "\tRunning bundle install:"
14
8
  @output = `cd #{context.folder_path} && bundle`
15
9
  puts "\t\t#{last_line}"
@@ -13,14 +13,8 @@ module RSGem
13
13
  #
14
14
  # https://github.com/rootstrap/tech-guides/blob/master/open-source/developing_gems.md#gemfilegemfilelockgemspec
15
15
  #
16
- class CleanGemfile
17
- attr_reader :context
18
-
19
- def initialize(context:)
20
- @context = context
21
- end
22
-
23
- def clean
16
+ class CleanGemfile < Base
17
+ def perform
24
18
  gemfile.gsub!(/gem .+\n/, '') # Remove all gem definitions
25
19
  gemfile.sub!(/\n\z/, '') # Remove last new line character
26
20
  write_to_gemfile
@@ -2,16 +2,10 @@
2
2
 
3
3
  module RSGem
4
4
  module Tasks
5
- class CleanGemspec
6
- attr_reader :context
7
-
5
+ class CleanGemspec < Base
8
6
  KEYS_TO_EMPTY = %w[summary description homepage].freeze
9
7
 
10
- def initialize(context:)
11
- @context = context
12
- end
13
-
14
- def clean
8
+ def perform
15
9
  comment_metadata!
16
10
  empty_keys!
17
11
  write
@@ -2,16 +2,15 @@
2
2
 
3
3
  module RSGem
4
4
  module Tasks
5
- class CreateGem
6
- attr_reader :context
7
-
8
- def initialize(context:)
9
- @context = context
10
- end
11
-
12
- def create
13
- system shell_command
14
- puts message
5
+ class CreateGem < Base
6
+ def perform
7
+ if system(shell_command)
8
+ puts message
9
+ else
10
+ puts "Failed to run `bundle gem'. "\
11
+ "Check bundler is installed in your system, or install it with `gem install bundler'"
12
+ exit false
13
+ end
15
14
  end
16
15
 
17
16
  private
@@ -29,7 +28,7 @@ module RSGem
29
28
 
30
29
  def shell_command
31
30
  [
32
- "bundle gem #{context.gem_name}",
31
+ "bundle gem #{context.gem_name} --test=rspec --coc --mit",
33
32
  bundler_options
34
33
  ].compact.join(' ')
35
34
  end
@@ -7,14 +7,8 @@ module RSGem
7
7
  #
8
8
  # https://github.com/rootstrap/tech-guides/blob/master/open-source/developing_gems.md#gemfilegemfilelockgemspec
9
9
  #
10
- class IgnoreGemfileLock
11
- attr_reader :context
12
-
13
- def initialize(context:)
14
- @context = context
15
- end
16
-
17
- def ignore
10
+ class IgnoreGemfileLock < Base
11
+ def perform
18
12
  gitignore << "\nGemfile.lock\n"
19
13
  write_to_gitignore
20
14
  puts "\tGemfile.lock added to .gitignore"
@@ -2,14 +2,8 @@
2
2
 
3
3
  module RSGem
4
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
5
+ class RunRubocop < Base
6
+ def perform
13
7
  puts "\tRubocop:"
14
8
  @output = `cd #{context.folder_path} && bundle exec rubocop -a`
15
9
  puts "\t\t#{last_line}"
@@ -11,14 +11,8 @@ module RSGem
11
11
  # - README.md
12
12
  # - lib/**/* (everything inside lib)
13
13
  #
14
- class SetBundledFiles
15
- attr_reader :context
16
-
17
- def initialize(context:)
18
- @context = context
19
- end
20
-
21
- def set
14
+ class SetBundledFiles < Base
15
+ def perform
22
16
  # Explaining the regular expression:
23
17
  # [spec.files][one or more white spaces][=][one or more white spaces][anything until "do"]
24
18
  # [new line][anything until new line]
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RSGem
4
+ module Tasks
5
+ class SimpleCovPostInstall < Base
6
+ def perform
7
+ spec_helper.sub!("require \"#{gem_name}\"", <<~RUBY)
8
+ require 'simplecov'
9
+
10
+ SimpleCov.start do
11
+ add_filter '/spec/'
12
+ end
13
+
14
+ require '#{gem_name}'
15
+ RUBY
16
+
17
+ write
18
+ end
19
+
20
+ private
21
+
22
+ def gem_name
23
+ context.gem_name
24
+ end
25
+
26
+ def spec_helper
27
+ @spec_helper ||= File.read(context.spec_helper_path)
28
+ end
29
+
30
+ def write
31
+ File.open(context.spec_helper_path, 'w') do |file|
32
+ file.puts spec_helper
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -2,7 +2,7 @@
2
2
 
3
3
  module RSGem
4
4
  MAJOR = 0
5
- MINOR = 1
6
- PATCH = 3
5
+ MINOR = 2
6
+ PATCH = 0
7
7
  VERSION = [MAJOR, MINOR, PATCH].join('.')
8
8
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rsgem
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Juan Manuel Ramallo
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-05-24 00:00:00.000000000 Z
11
+ date: 2020-06-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-cli
@@ -146,6 +146,7 @@ files:
146
146
  - lib/rsgem/support/travis.yml
147
147
  - lib/rsgem/tasks/add_code_analysis.rb
148
148
  - lib/rsgem/tasks/add_dependency.rb
149
+ - lib/rsgem/tasks/base.rb
149
150
  - lib/rsgem/tasks/bundle_dependencies.rb
150
151
  - lib/rsgem/tasks/clean_gemfile.rb
151
152
  - lib/rsgem/tasks/clean_gemspec.rb
@@ -153,6 +154,7 @@ files:
153
154
  - lib/rsgem/tasks/ignore_gemfile_lock.rb
154
155
  - lib/rsgem/tasks/run_rubocop.rb
155
156
  - lib/rsgem/tasks/set_bundled_files.rb
157
+ - lib/rsgem/tasks/simple_cov_post_install.rb
156
158
  - lib/rsgem/version.rb
157
159
  homepage: https://github.com/rootstrap/rsgem
158
160
  licenses: