gem_generator 0.2.0 → 0.3.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8cfd12ba054676e203daa371f7ffb27b93513a4c77833df17cea52f255a82f1e
4
- data.tar.gz: 172676284e80200664ae9f9652f359544a5d23332f3b00a56b48896a75b8a738
3
+ metadata.gz: 7f3a231a663b783f7bf00b7faecbe2e0ba9a83758889f737850464d8787417b1
4
+ data.tar.gz: 284e0c140d77a1601e7c4c0d8ede966761de87252ea4bdede6a40fdeddf3da80
5
5
  SHA512:
6
- metadata.gz: 25311e68bd697b2f3618d5bc6fd695c90f7fcf82a3ae14b02387cd1cb17caf0f126822ea9093abf7e9fcc689dcb76b0e03cccfd7be1d22aac97fe502405e0f35
7
- data.tar.gz: c1047aa59e76117cdd5364b2852230015790d3b7333d12254be8744c772438dfbd65e742a38ec0558fc49de27898ec7c2d1f097817a3d8f556999acd005eeefc
6
+ metadata.gz: 8c93e384412e88394adf30eb9dd7e4ad80ef8d1b4cd6206d77cb46d4fe75e01fc9fab8086a91c7710fb6ee680dd9816b99f3f0785fb95da01b295d6f7859084c
7
+ data.tar.gz: 16b39763cafaa19b5fe6f760d6106d0e0df9d898bfba0197ce883a1c4f0a5d352a64e60984daf34b8d24e4333dbfec636352181e944885cfcf9d976f131df82c
data/CHANGELOG.md CHANGED
@@ -2,6 +2,17 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 0.3.1 (2021-11-07)
6
+
7
+ * Require runtime depepndencies.
8
+
9
+ ## 0.3.0 (2021-11-01)
10
+
11
+ * Install Bundler template dependencies from unbundled environment.
12
+ It should fix issues with templates specs, [example](https://github.com/lostisland/faraday-middleware-template/pull/3).
13
+ * Speed up tests about `--git` option.
14
+ * Update development dependencies.
15
+
5
16
  ## 0.2.0 (2021-10-18)
6
17
 
7
18
  * Add `--git` option.
@@ -0,0 +1,149 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'yaml'
4
+ require 'memery'
5
+ require 'gorilla_patch/blank'
6
+ require 'gorilla_patch/inflections'
7
+
8
+ module GemGenerator
9
+ ## Main CLI command for Gem Generator
10
+ class Command < Clamp::Command
11
+ ## Private instance methods for processing template files (copying, renaming, rendering)
12
+ module ProcessFiles
13
+ ## Class for a single object which should be a scope in render
14
+ class RenderVariables
15
+ include Memery
16
+
17
+ using GorillaPatch::Blank
18
+ using GorillaPatch::Inflections
19
+
20
+ attr_reader :name, :indentation, :summary
21
+
22
+ def initialize(name, namespace_option, indentation, summary)
23
+ @name = name
24
+ @namespace_option = namespace_option
25
+ @indentation = indentation
26
+ @summary = summary
27
+
28
+ ## Call to be sure that this is checked before author fields
29
+ github_namespace
30
+ end
31
+
32
+ ## `public :binding` and `send :binding` return caller binding
33
+ ## This is from ERB documentation: https://ruby-doc.org/core-2.7.2/Binding.html
34
+ # rubocop:disable Naming/AccessorMethodName
35
+ def get_binding
36
+ binding
37
+ end
38
+ # rubocop:enable Naming/AccessorMethodName
39
+
40
+ memoize def summary_string
41
+ quote = summary.include?("'") ? '"' : "'"
42
+ "#{quote}#{summary}#{quote}"
43
+ end
44
+
45
+ memoize def description
46
+ summary.match?(/[.?!]$/) ? summary : "#{summary}."
47
+ end
48
+
49
+ memoize def path
50
+ name.tr('-', '/')
51
+ end
52
+
53
+ memoize def title
54
+ name.split(/[-_]/).map(&:camelize).join(' ')
55
+ end
56
+
57
+ memoize def module_name
58
+ path.camelize
59
+ end
60
+
61
+ memoize def modules
62
+ module_name.split('::')
63
+ end
64
+
65
+ memoize def version_constant
66
+ "#{module_name}::VERSION"
67
+ end
68
+
69
+ memoize def github_path
70
+ "#{github_namespace}/#{name}"
71
+ end
72
+
73
+ memoize def github_namespace_uri
74
+ "https://github.com/#{github_namespace}"
75
+ end
76
+
77
+ memoize def github_uri
78
+ "https://github.com/#{github_path}"
79
+ end
80
+
81
+ EXAMPLE_VALUES = {
82
+ name: 'My Name',
83
+ email: 'my.email@example.com'
84
+ }.freeze
85
+ private_constant :EXAMPLE_VALUES
86
+
87
+ %i[name email].each do |property|
88
+ method_name = "author_#{property}"
89
+
90
+ define_method method_name do
91
+ result = config.dig(:author, property) || `git config --get user.#{property}`.chomp
92
+
93
+ return result unless result.blank?
94
+
95
+ abort <<~TEXT
96
+ You have to specify project's author #{property}.
97
+ You can use `git config user.#{property} "#{EXAMPLE_VALUES[property]}"`, or create a configuration file.
98
+ Check the README.
99
+ TEXT
100
+ end
101
+
102
+ memoize method_name
103
+ end
104
+
105
+ memoize def author_name_string
106
+ quote = author_name.include?("'") ? '"' : "'"
107
+ "#{quote}#{author_name}#{quote}"
108
+ end
109
+
110
+ private
111
+
112
+ memoize def github_namespace
113
+ result = @namespace_option || config[:namespace]
114
+
115
+ return result unless result.blank?
116
+
117
+ abort <<~TEXT
118
+ You have to specify project's namespace on GitHub.
119
+ You can use `--namespace` option, or create a configuration file.
120
+ Check the README.
121
+ TEXT
122
+ end
123
+
124
+ memoize def config
125
+ config_file = find_config_file
126
+ return {} unless config_file
127
+
128
+ YAML.load_file config_file
129
+ end
130
+
131
+ def find_config_file
132
+ config_lookup_directory = Dir.getwd
133
+
134
+ until (
135
+ config_file = Dir.glob(
136
+ File.join(config_lookup_directory, '.gem_generator.y{a,}ml'), File::FNM_DOTMATCH
137
+ ).first
138
+ ) || config_lookup_directory == '/'
139
+ config_lookup_directory = File.dirname config_lookup_directory
140
+ end
141
+
142
+ config_file
143
+ end
144
+ end
145
+
146
+ private_constant :RenderVariables
147
+ end
148
+ end
149
+ end
@@ -0,0 +1,76 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'process_files/render_variables'
4
+
5
+ module GemGenerator
6
+ ## Main CLI command for Gem Generator
7
+ class Command < Clamp::Command
8
+ ## Private instance methods for processing template files (copying, renaming, rendering)
9
+ module ProcessFiles
10
+ private
11
+
12
+ def process_files
13
+ copy_files
14
+
15
+ begin
16
+ @render_variables = RenderVariables.new name, namespace, indentation, @summary
17
+
18
+ rename_files
19
+
20
+ render_files
21
+ rescue SystemExit => e
22
+ FileUtils.rm_r @directory
23
+ raise e
24
+ end
25
+ end
26
+
27
+ def copy_files
28
+ puts 'Copying files...'
29
+
30
+ FileUtils.cp_r template, @directory
31
+
32
+ FileUtils.rm_rf "#{@directory}/.git"
33
+ end
34
+
35
+ def rename_files
36
+ puts 'Renaming files...'
37
+
38
+ { 'gem_name' => @render_variables.name, 'gem_path' => @render_variables.path }
39
+ .each do |template_name, real_name|
40
+ Dir["#{@directory}/**/*#{template_name}*"].each do |file_name|
41
+ new_file_name =
42
+ @directory + file_name.delete_prefix(@directory).gsub(template_name, real_name)
43
+
44
+ FileUtils.mkdir_p File.dirname new_file_name
45
+
46
+ File.rename file_name, new_file_name
47
+ end
48
+ end
49
+ end
50
+
51
+ def render_files
52
+ puts 'Rendering files...'
53
+
54
+ Dir.glob("#{@directory}/**/*.erb", File::FNM_DOTMATCH).each do |template_file|
55
+ ## Read a template file content and render it
56
+ content =
57
+ ERB.new(File.read(template_file), trim_mode: '-').result(@render_variables.get_binding)
58
+
59
+ ## Replace tabs with spaces if necessary
60
+ content.gsub!(/^\t+/) { |tabs| ' ' * tabs.count("\t") } if indentation == 'spaces'
61
+
62
+ ## Render variables in file name
63
+ real_pathname = Pathname.new(template_file).sub_ext('')
64
+
65
+ ## Rename template file
66
+ File.rename template_file, real_pathname
67
+
68
+ ## Update file content
69
+ File.write real_pathname, content
70
+ end
71
+ end
72
+ end
73
+
74
+ private_constant :ProcessFiles
75
+ end
76
+ end
@@ -1,11 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'bundler'
3
4
  require 'clamp'
4
5
  require 'erb'
5
6
  require 'fileutils'
6
7
  require 'pathname'
8
+ require 'tmpdir'
7
9
 
8
- require_relative 'render_variables'
10
+ require_relative 'command/process_files'
9
11
 
10
12
  ## https://github.com/mdub/clamp#allowing-options-after-parameters
11
13
  Clamp.allow_options_after_parameters = true
@@ -13,6 +15,8 @@ Clamp.allow_options_after_parameters = true
13
15
  module GemGenerator
14
16
  ## Main CLI command for Gem Generator
15
17
  class Command < Clamp::Command
18
+ include ProcessFiles
19
+
16
20
  parameter 'NAME', 'name of a new gem'
17
21
  parameter 'TEMPLATE', 'template path of a new gem'
18
22
 
@@ -90,68 +94,6 @@ module GemGenerator
90
94
  self.template = File.join @git_tmp_dir, 'template'
91
95
  end
92
96
 
93
- def process_files
94
- copy_files
95
-
96
- begin
97
- @render_variables = RenderVariables.new name, namespace, indentation, @summary
98
-
99
- rename_files
100
-
101
- render_files
102
- rescue SystemExit => e
103
- FileUtils.rm_r @directory
104
- raise e
105
- end
106
- end
107
-
108
- def copy_files
109
- puts 'Copying files...'
110
-
111
- FileUtils.cp_r template, @directory
112
-
113
- FileUtils.rm_rf "#{@directory}/.git"
114
- end
115
-
116
- def rename_files
117
- puts 'Renaming files...'
118
-
119
- { 'gem_name' => @render_variables.name, 'gem_path' => @render_variables.path }
120
- .each do |template_name, real_name|
121
- Dir["#{@directory}/**/*#{template_name}*"].each do |file_name|
122
- new_file_name =
123
- @directory + file_name.delete_prefix(@directory).gsub(template_name, real_name)
124
-
125
- FileUtils.mkdir_p File.dirname new_file_name
126
-
127
- File.rename file_name, new_file_name
128
- end
129
- end
130
- end
131
-
132
- def render_files
133
- puts 'Rendering files...'
134
-
135
- Dir.glob("#{@directory}/**/*.erb", File::FNM_DOTMATCH).each do |template_file|
136
- ## Read a template file content and render it
137
- content =
138
- ERB.new(File.read(template_file), trim_mode: '-').result(@render_variables.get_binding)
139
-
140
- ## Replace tabs with spaces if necessary
141
- ## TODO: Get spaces count from `.editorconfig` file
142
- content.gsub!(/^\t+/) { |tabs| ' ' * tabs.count("\t") } if indentation == 'spaces'
143
-
144
- ## Render variables in file name
145
- real_pathname = Pathname.new(template_file).sub_ext('')
146
-
147
- ## Rename template file
148
- File.rename template_file, real_pathname
149
-
150
- ## Update file content
151
- File.write real_pathname, content
152
- end
153
- end
154
-
155
97
  def initialize_git
156
98
  puts 'Initializing git...'
157
99
 
@@ -165,7 +107,10 @@ module GemGenerator
165
107
  puts 'Installing dependencies...'
166
108
 
167
109
  Dir.chdir name do
168
- system 'bundle update'
110
+ ## Helpful for specs of templates, probably somewhere else
111
+ Bundler.with_unbundled_env do
112
+ system 'bundle update'
113
+ end
169
114
 
170
115
  system 'npm install' if File.exist? 'package.json'
171
116
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GemGenerator
4
- VERSION = '0.2.0'
4
+ VERSION = '0.3.1'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gem_generator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander Popov
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-10-18 00:00:00.000000000 Z
11
+ date: 2021-11-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: alt_memery
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: clamp
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -80,20 +94,6 @@ dependencies:
80
94
  - - "~>"
81
95
  - !ruby/object:Gem::Version
82
96
  version: '3.0'
83
- - !ruby/object:Gem::Dependency
84
- name: bundler
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - "~>"
88
- - !ruby/object:Gem::Version
89
- version: '2.0'
90
- type: :development
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - "~>"
95
- - !ruby/object:Gem::Version
96
- version: '2.0'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: bundler-audit
99
99
  requirement: !ruby/object:Gem::Requirement
@@ -114,14 +114,14 @@ dependencies:
114
114
  requirements:
115
115
  - - "~>"
116
116
  - !ruby/object:Gem::Version
117
- version: 0.10.0
117
+ version: 0.11.0
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
122
  - - "~>"
123
123
  - !ruby/object:Gem::Version
124
- version: 0.10.0
124
+ version: 0.11.0
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: toys
127
127
  requirement: !ruby/object:Gem::Requirement
@@ -249,14 +249,15 @@ files:
249
249
  - README.md
250
250
  - exe/gem_generator
251
251
  - lib/gem_generator/command.rb
252
- - lib/gem_generator/render_variables.rb
252
+ - lib/gem_generator/command/process_files.rb
253
+ - lib/gem_generator/command/process_files/render_variables.rb
253
254
  - lib/gem_generator/version.rb
254
255
  homepage: https://github.com/AlexWayfer/gem_generator
255
256
  licenses:
256
257
  - MIT
257
258
  metadata:
258
259
  bug_tracker_uri: https://github.com/AlexWayfer/gem_generator/issues
259
- changelog_uri: https://github.com/AlexWayfer/gem_generator/blob/v0.2.0/CHANGELOG.md
260
+ changelog_uri: https://github.com/AlexWayfer/gem_generator/blob/v0.3.1/CHANGELOG.md
260
261
  homepage_uri: https://github.com/AlexWayfer/gem_generator
261
262
  source_code_uri: https://github.com/AlexWayfer/gem_generator
262
263
  post_install_message:
@@ -1,141 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'yaml'
4
- require 'memery'
5
- require 'gorilla_patch/blank'
6
- require 'gorilla_patch/inflections'
7
-
8
- module GemGenerator
9
- ## Class for a single object which should be a scope in render
10
- class RenderVariables
11
- include Memery
12
-
13
- using GorillaPatch::Blank
14
- using GorillaPatch::Inflections
15
-
16
- attr_reader :name, :indentation, :summary
17
-
18
- def initialize(name, namespace_option, indentation, summary)
19
- @name = name
20
- @namespace_option = namespace_option
21
- @indentation = indentation
22
- @summary = summary
23
-
24
- ## Call to be sure that this is checked before author fields
25
- github_namespace
26
- end
27
-
28
- ## `public :binding` and `send :binding` return caller binding
29
- ## This is from ERB documentation: https://ruby-doc.org/core-2.7.2/Binding.html
30
- # rubocop:disable Naming/AccessorMethodName
31
- def get_binding
32
- binding
33
- end
34
- # rubocop:enable Naming/AccessorMethodName
35
-
36
- memoize def summary_string
37
- quote = summary.include?("'") ? '"' : "'"
38
- "#{quote}#{summary}#{quote}"
39
- end
40
-
41
- memoize def description
42
- summary.match?(/[.?!]$/) ? summary : "#{summary}."
43
- end
44
-
45
- memoize def path
46
- name.tr('-', '/')
47
- end
48
-
49
- memoize def title
50
- name.split(/[-_]/).map(&:camelize).join(' ')
51
- end
52
-
53
- memoize def module_name
54
- path.camelize
55
- end
56
-
57
- memoize def modules
58
- module_name.split('::')
59
- end
60
-
61
- memoize def version_constant
62
- "#{module_name}::VERSION"
63
- end
64
-
65
- memoize def github_path
66
- "#{github_namespace}/#{name}"
67
- end
68
-
69
- memoize def github_namespace_uri
70
- "https://github.com/#{github_namespace}"
71
- end
72
-
73
- memoize def github_uri
74
- "https://github.com/#{github_path}"
75
- end
76
-
77
- EXAMPLE_VALUES = {
78
- name: 'My Name',
79
- email: 'my.email@example.com'
80
- }.freeze
81
- private_constant :EXAMPLE_VALUES
82
-
83
- %i[name email].each do |property|
84
- method_name = "author_#{property}"
85
-
86
- define_method method_name do
87
- result = config.dig(:author, property) || `git config --get user.#{property}`.chomp
88
-
89
- return result unless result.blank?
90
-
91
- abort <<~TEXT
92
- You have to specify project's author #{property}.
93
- You can use `git config user.#{property} "#{EXAMPLE_VALUES[property]}"`, or create a configuration file.
94
- Check the README.
95
- TEXT
96
- end
97
-
98
- memoize method_name
99
- end
100
-
101
- memoize def author_name_string
102
- quote = author_name.include?("'") ? '"' : "'"
103
- "#{quote}#{author_name}#{quote}"
104
- end
105
-
106
- private
107
-
108
- memoize def github_namespace
109
- result = @namespace_option || config[:namespace]
110
-
111
- return result unless result.blank?
112
-
113
- abort <<~TEXT
114
- You have to specify project's namespace on GitHub.
115
- You can use `--namespace` option, or create a configuration file.
116
- Check the README.
117
- TEXT
118
- end
119
-
120
- memoize def config
121
- config_file = find_config_file
122
- return {} unless config_file
123
-
124
- YAML.load_file config_file
125
- end
126
-
127
- def find_config_file
128
- config_lookup_directory = Dir.getwd
129
-
130
- until (
131
- config_file = Dir.glob(
132
- File.join(config_lookup_directory, '.gem_generator.y{a,}ml'), File::FNM_DOTMATCH
133
- ).first
134
- ) || config_lookup_directory == '/'
135
- config_lookup_directory = File.dirname config_lookup_directory
136
- end
137
-
138
- config_file
139
- end
140
- end
141
- end