example_file 0.2.0 → 0.4.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: c27c0c37aed4d33ed7fdbaddc5ea08add611a904c5adeb588abc42178de8b2a4
4
- data.tar.gz: 26812fb041b9727dc718da8f46a6e8e70e7ea58f3d684625fd9ccdbd28898cd8
3
+ metadata.gz: dd44dec5c2bf7075656ebdd405b0960221dcba6dad77e376e23015bdabebd3b8
4
+ data.tar.gz: 1c1e5659cea072d168309c0b0e30feaca6ada071f7e9517342a23851346f5ae7
5
5
  SHA512:
6
- metadata.gz: e8008ba9546a72a9e79deafca628ed45cd77e634e25f903fa16f37ee3a68d8577f9ac652358f7ff3c9fdfde8835ad41121b63ac86c1297533f39b6d9645f40c2
7
- data.tar.gz: d2159ad14738f0afda3f65a6e3d48b5d99ef8e82edcf07e25601c260768de6c6c01459822eb5e50a4d1b47eb2bbca2638be26fe861d9ecf79de6b1ae0c88ee5c
6
+ metadata.gz: 2ad40a576dd715a6b4e30c239bc1ccde7872b0cbdd7deec4fe308073711188640af0d3fbab410db104e0fea2c97f5613208980ac3f2c92d309c41733e66196bb
7
+ data.tar.gz: 376ff78bf8f127348e0dc68f22c83f5031cbec931b525d1ee8df2379303170241b1ec0c67ffff9d4ee216cd601f98d3bd971a57a60c5a928015adcf82614a839
data/CHANGELOG.md CHANGED
@@ -1,9 +1,36 @@
1
1
  # Changelog
2
2
 
3
- ## master (unreleased)
3
+ ## Unreleased
4
+
5
+ ## 0.4.0 (2022-09-29)
6
+
7
+ * Drop Ruby 2.5 support.
8
+ * Add Ruby 3.1 support.
9
+ * Add `#initialize_regular_file` method.
10
+ * Update development dependencies.
11
+ * Resolve new RuboCop offenses.
12
+ * Add `bundle-audit` CI task.
13
+
14
+ ## 0.3.1 (2021-04-16)
15
+
16
+ * Fix Ruby warnings (and specs fails).
17
+
18
+ ## 0.3.0 (2021-04-16)
19
+
20
+ * Remake the question from "Do you want to edit?" to "What to do?".
21
+ * Add `replace-and-edit` answer.
22
+ * Change menu layout from inline to rows with numbers.
23
+ I have no idea how to make easier shortcut for `replace-and-edit`.
24
+ * Add Ruby 3 support and CI.
25
+ * Update development dependencies.
4
26
 
5
27
  ## 0.2.0 (2020-09-30)
6
28
 
29
+ * Abort program on try to edit file without `$EDITOR` environment variable.
30
+ Don't rely on external code, also abort only on try to edit.
31
+ * Update dependencies.
32
+ * Improve Cirrus CI config.
33
+
7
34
  ## 0.1.0 (2020-06-02)
8
35
 
9
36
  * Initial release.
data/README.md CHANGED
@@ -1,11 +1,11 @@
1
1
  # Example File
2
2
 
3
3
  ![Cirrus CI - Base Branch Build Status](https://img.shields.io/cirrus/github/AlexWayfer/example_file?style=flat-square)
4
- [![Codecov branch](https://img.shields.io/codecov/c/github/AlexWayfer/example_file/master.svg?style=flat-square)](https://codecov.io/gh/AlexWayfer/example_file)
4
+ [![Codecov branch](https://img.shields.io/codecov/c/github/AlexWayfer/example_file/main.svg?style=flat-square)](https://codecov.io/gh/AlexWayfer/example_file)
5
5
  [![Code Climate](https://img.shields.io/codeclimate/maintainability/AlexWayfer/example_file.svg?style=flat-square)](https://codeclimate.com/github/AlexWayfer/example_file)
6
6
  ![Depfu](https://img.shields.io/depfu/AlexWayfer/example_file?style=flat-square)
7
- [![Inline docs](https://inch-ci.org/github/AlexWayfer/example_file.svg?branch=master)](https://inch-ci.org/github/AlexWayfer/example_file)
8
- [![license](https://img.shields.io/github/license/AlexWayfer/example_file.svg?style=flat-square)](https://github.com/AlexWayfer/example_file/blob/master/LICENSE.txt)
7
+ [![Inline docs](https://inch-ci.org/github/AlexWayfer/example_file.svg?branch=main)](https://inch-ci.org/github/AlexWayfer/example_file)
8
+ [![license](https://img.shields.io/github/license/AlexWayfer/example_file.svg?style=flat-square)](https://github.com/AlexWayfer/example_file/blob/main/LICENSE.txt)
9
9
  [![Gem](https://img.shields.io/gem/v/example_file.svg?style=flat-square)](https://rubygems.org/gems/example_file)
10
10
 
11
11
  Class helper for example files. Usually it's the alternative
@@ -61,7 +61,8 @@ It'll act in these ways:
61
61
  * ask for a further action:
62
62
  * open the editor;
63
63
  * just update regular without changes;
64
- * or replace regular file with a content from new example file.
64
+ * replace regular file with a content from new example file;
65
+ * or replace and then open the editor.
65
66
  * If there is regular file with file modified time after example file:
66
67
  * do nothing.
67
68
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class ExampleFile
4
- VERSION = '0.2.0'
4
+ VERSION = '0.4.0'
5
5
  end
data/lib/example_file.rb CHANGED
@@ -18,29 +18,41 @@ class ExampleFile
18
18
  end
19
19
  end
20
20
 
21
+ attr_reader :choices
22
+ attr_writer :question_prefix
23
+
21
24
  def initialize(file_name)
22
25
  @file_name = file_name
23
26
  @regular_file_name = @file_name.sub SUFFIX, ''
24
27
 
25
- @basename =
26
- Paint[File.basename(@file_name), :green, :bold]
27
- @regular_basename =
28
- Paint[File.basename(@regular_file_name), :red, :bold]
28
+ @basename = Paint[File.basename(@file_name), :green, :bold]
29
+ @regular_basename = Paint[File.basename(@regular_file_name), :red, :bold]
30
+
31
+ @choices = DEFAULT_CHOICES.dup
32
+ @question_prefix = nil
29
33
  end
30
34
 
31
35
  def actualize_regular_file
32
36
  return create_regular_file unless regular_file_exist?
33
37
 
34
- return unless new?
38
+ return unless updated?
35
39
 
36
40
  return update_regular_file if diff.chomp.empty?
37
41
 
38
42
  ask_question_and_make_actions
39
43
  end
40
44
 
45
+ def initialize_regular_file
46
+ if File.exist? @regular_file_name
47
+ raise "File `#{File.basename(@regular_file_name)}` already exists"
48
+ end
49
+
50
+ FileUtils.cp @file_name, @regular_file_name
51
+ end
52
+
41
53
  private
42
54
 
43
- def new?
55
+ def updated?
44
56
  File.mtime(@file_name) > File.mtime(@regular_file_name)
45
57
  end
46
58
 
@@ -49,7 +61,7 @@ class ExampleFile
49
61
  end
50
62
 
51
63
  def create_regular_file
52
- FileUtils.cp @file_name, @regular_file_name
64
+ initialize_regular_file
53
65
  edit_file @regular_file_name
54
66
  end
55
67
 
@@ -63,26 +75,31 @@ class ExampleFile
63
75
  .to_s(:color)
64
76
  end
65
77
 
66
- CHOICES = {
67
- yes: proc { edit_file @regular_file_name },
78
+ DEFAULT_CHOICES = {
79
+ edit: proc { edit_file @regular_file_name },
68
80
  replace: proc { rewrite_regular_file },
69
- no: proc do
81
+ 'replace-and-edit': proc do
82
+ rewrite_regular_file
83
+ edit_file @regular_file_name
84
+ end,
85
+ keep: proc do
70
86
  update_regular_file
71
87
  puts 'File modified time updated'
72
88
  end
73
89
  }.freeze
74
90
 
75
- private_constant :CHOICES
91
+ private_constant :DEFAULT_CHOICES
76
92
 
77
93
  def ask_question_and_make_actions
78
94
  puts warning_with_diff
79
95
 
80
96
  HIGHLINE.choose do |menu|
81
- menu.layout = :one_line
97
+ ## I don't know how to catch complex options like `replace-and-edit`, via shortcut like `rae`
98
+ # menu.layout = :one_line
82
99
 
83
- menu.prompt = "Do you want to edit #{@regular_basename} ? "
100
+ menu.header = "What to do with #{@regular_basename} "
84
101
 
85
- CHOICES.each do |answer, block|
102
+ choices.each do |answer, block|
86
103
  menu.choice(answer) { instance_exec(&block) }
87
104
  end
88
105
  end
@@ -90,7 +107,7 @@ class ExampleFile
90
107
 
91
108
  def warning_with_diff
92
109
  <<~WARN
93
- #{@basename} was modified after #{@regular_basename}.
110
+ #{@question_prefix}#{@basename} was modified after #{@regular_basename}.
94
111
 
95
112
  ```diff
96
113
  #{diff}
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: example_file
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander Popov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-09-30 00:00:00.000000000 Z
11
+ date: 2022-09-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: diffy
@@ -81,47 +81,47 @@ dependencies:
81
81
  - !ruby/object:Gem::Version
82
82
  version: '2.0'
83
83
  - !ruby/object:Gem::Dependency
84
- name: gem_toys
84
+ name: bundler-audit
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: 0.4.0
89
+ version: 0.9.0
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: 0.4.0
96
+ version: 0.9.0
97
97
  - !ruby/object:Gem::Dependency
98
- name: toys
98
+ name: gem_toys
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
101
  - - "~>"
102
102
  - !ruby/object:Gem::Version
103
- version: 0.11.0
103
+ version: 0.12.1
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
- version: 0.11.0
110
+ version: 0.12.1
111
111
  - !ruby/object:Gem::Dependency
112
- name: codecov
112
+ name: toys
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
115
  - - "~>"
116
116
  - !ruby/object:Gem::Version
117
- version: 0.2.0
117
+ version: 0.13.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.2.0
124
+ version: 0.13.0
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: rspec
127
127
  requirement: !ruby/object:Gem::Requirement
@@ -142,28 +142,42 @@ dependencies:
142
142
  requirements:
143
143
  - - "~>"
144
144
  - !ruby/object:Gem::Version
145
- version: 0.19.0
145
+ version: 0.21.2
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: 0.21.2
153
+ - !ruby/object:Gem::Dependency
154
+ name: simplecov-cobertura
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - "~>"
158
+ - !ruby/object:Gem::Version
159
+ version: '2.1'
146
160
  type: :development
147
161
  prerelease: false
148
162
  version_requirements: !ruby/object:Gem::Requirement
149
163
  requirements:
150
164
  - - "~>"
151
165
  - !ruby/object:Gem::Version
152
- version: 0.19.0
166
+ version: '2.1'
153
167
  - !ruby/object:Gem::Dependency
154
168
  name: rubocop
155
169
  requirement: !ruby/object:Gem::Requirement
156
170
  requirements:
157
171
  - - "~>"
158
172
  - !ruby/object:Gem::Version
159
- version: 0.92.0
173
+ version: 1.36.0
160
174
  type: :development
161
175
  prerelease: false
162
176
  version_requirements: !ruby/object:Gem::Requirement
163
177
  requirements:
164
178
  - - "~>"
165
179
  - !ruby/object:Gem::Version
166
- version: 0.92.0
180
+ version: 1.36.0
167
181
  - !ruby/object:Gem::Dependency
168
182
  name: rubocop-performance
169
183
  requirement: !ruby/object:Gem::Requirement
@@ -184,14 +198,14 @@ dependencies:
184
198
  requirements:
185
199
  - - "~>"
186
200
  - !ruby/object:Gem::Version
187
- version: '1.0'
201
+ version: '2.0'
188
202
  type: :development
189
203
  prerelease: false
190
204
  version_requirements: !ruby/object:Gem::Requirement
191
205
  requirements:
192
206
  - - "~>"
193
207
  - !ruby/object:Gem::Version
194
- version: '1.0'
208
+ version: '2.0'
195
209
  description: |
196
210
  Class helper for example files.
197
211
  Usualy it's the alternative to environment variables (and `.env` files).
@@ -214,7 +228,8 @@ licenses:
214
228
  metadata:
215
229
  source_code_uri: https://github.com/AlexWayfer/example_file
216
230
  homepage_uri: https://github.com/AlexWayfer/example_file
217
- changelog_uri: https://github.com/AlexWayfer/example_file/blob/master/CHANGELOG.md
231
+ changelog_uri: https://github.com/AlexWayfer/example_file/blob/main/CHANGELOG.md
232
+ rubygems_mfa_required: 'true'
218
233
  post_install_message:
219
234
  rdoc_options: []
220
235
  require_paths:
@@ -223,14 +238,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
223
238
  requirements:
224
239
  - - ">="
225
240
  - !ruby/object:Gem::Version
226
- version: '2.5'
241
+ version: '2.6'
242
+ - - "<"
243
+ - !ruby/object:Gem::Version
244
+ version: '4'
227
245
  required_rubygems_version: !ruby/object:Gem::Requirement
228
246
  requirements:
229
247
  - - ">="
230
248
  - !ruby/object:Gem::Version
231
249
  version: '0'
232
250
  requirements: []
233
- rubygems_version: 3.1.2
251
+ rubygems_version: 3.3.7
234
252
  signing_key:
235
253
  specification_version: 4
236
254
  summary: Class helper for example files