example_file 0.2.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +16 -0
- data/README.md +2 -1
- data/lib/example_file.rb +23 -14
- data/lib/example_file/version.rb +1 -1
- metadata +16 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 49937d788050f9c348a9a71cff14864470ea4c1a10e6580d94e14f7fe7b59fe9
|
4
|
+
data.tar.gz: 07bc86ec61da5085249a6c242c46f78b625b408196d08f40b3d1a06b203e509e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a23aa29a4e08c6e7aeebe27bd6a93199ede3611529e226156a09573b6488f383e46eb7c17bfc8fe3cd629e0cdd31b786a3535ea8c8c55e6f7a78f0377c15a809
|
7
|
+
data.tar.gz: cb7298effcef870ab313fb7dd1469472c8b8dd925d4ba67bca3dce5829cf6411989e9c0d25ed49a9139d10356bb6baceaf23e103fa6febd15476fd7d707d20d8
|
data/CHANGELOG.md
CHANGED
@@ -2,8 +2,24 @@
|
|
2
2
|
|
3
3
|
## master (unreleased)
|
4
4
|
|
5
|
+
## 0.3.1 (2021-04-16)
|
6
|
+
|
7
|
+
## 0.3.0 (2021-04-16)
|
8
|
+
|
9
|
+
* Remake the question from "Do you want to edit?" to "What to do?".
|
10
|
+
* Add `replace-and-edit` answer.
|
11
|
+
* Change menu layout from inline to rows with numbers.
|
12
|
+
I have no idea how to make easier shortcut for `replace-and-edit`.
|
13
|
+
* Add Ruby 3 support and CI.
|
14
|
+
* Update development dependencies.
|
15
|
+
|
5
16
|
## 0.2.0 (2020-09-30)
|
6
17
|
|
18
|
+
* Abort program on try to edit file without `$EDITOR` environment variable.
|
19
|
+
Don't rely on external code, also abort only on try to edit.
|
20
|
+
* Update dependencies.
|
21
|
+
* Improve Cirrus CI config.
|
22
|
+
|
7
23
|
## 0.1.0 (2020-06-02)
|
8
24
|
|
9
25
|
* Initial release.
|
data/README.md
CHANGED
@@ -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
|
-
*
|
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
|
|
data/lib/example_file.rb
CHANGED
@@ -18,20 +18,24 @@ 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
|
-
|
27
|
-
|
28
|
-
|
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
|
38
|
+
return unless updated?
|
35
39
|
|
36
40
|
return update_regular_file if diff.chomp.empty?
|
37
41
|
|
@@ -40,7 +44,7 @@ class ExampleFile
|
|
40
44
|
|
41
45
|
private
|
42
46
|
|
43
|
-
def
|
47
|
+
def updated?
|
44
48
|
File.mtime(@file_name) > File.mtime(@regular_file_name)
|
45
49
|
end
|
46
50
|
|
@@ -63,26 +67,31 @@ class ExampleFile
|
|
63
67
|
.to_s(:color)
|
64
68
|
end
|
65
69
|
|
66
|
-
|
67
|
-
|
70
|
+
DEFAULT_CHOICES = {
|
71
|
+
edit: proc { edit_file @regular_file_name },
|
68
72
|
replace: proc { rewrite_regular_file },
|
69
|
-
|
73
|
+
'replace-and-edit': proc do
|
74
|
+
rewrite_regular_file
|
75
|
+
edit_file @regular_file_name
|
76
|
+
end,
|
77
|
+
keep: proc do
|
70
78
|
update_regular_file
|
71
79
|
puts 'File modified time updated'
|
72
80
|
end
|
73
81
|
}.freeze
|
74
82
|
|
75
|
-
private_constant :
|
83
|
+
private_constant :DEFAULT_CHOICES
|
76
84
|
|
77
85
|
def ask_question_and_make_actions
|
78
86
|
puts warning_with_diff
|
79
87
|
|
80
88
|
HIGHLINE.choose do |menu|
|
81
|
-
|
89
|
+
## I don't know how to catch complex options like `replace-and-edit`, via shortcut like `rae`
|
90
|
+
# menu.layout = :one_line
|
82
91
|
|
83
|
-
menu.
|
92
|
+
menu.header = "What to do with #{@regular_basename} "
|
84
93
|
|
85
|
-
|
94
|
+
choices.each do |answer, block|
|
86
95
|
menu.choice(answer) { instance_exec(&block) }
|
87
96
|
end
|
88
97
|
end
|
@@ -90,7 +99,7 @@ class ExampleFile
|
|
90
99
|
|
91
100
|
def warning_with_diff
|
92
101
|
<<~WARN
|
93
|
-
#{@basename} was modified after #{@regular_basename}.
|
102
|
+
#{@question_prefix}#{@basename} was modified after #{@regular_basename}.
|
94
103
|
|
95
104
|
```diff
|
96
105
|
#{diff}
|
data/lib/example_file/version.rb
CHANGED
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.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexander Popov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-04-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: diffy
|
@@ -86,14 +86,14 @@ dependencies:
|
|
86
86
|
requirements:
|
87
87
|
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: 0.
|
89
|
+
version: 0.8.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.
|
96
|
+
version: 0.8.0
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: toys
|
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.
|
117
|
+
version: 0.5.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.
|
124
|
+
version: 0.5.0
|
125
125
|
- !ruby/object:Gem::Dependency
|
126
126
|
name: rspec
|
127
127
|
requirement: !ruby/object:Gem::Requirement
|
@@ -142,28 +142,28 @@ dependencies:
|
|
142
142
|
requirements:
|
143
143
|
- - "~>"
|
144
144
|
- !ruby/object:Gem::Version
|
145
|
-
version: 0.
|
145
|
+
version: 0.21.2
|
146
146
|
type: :development
|
147
147
|
prerelease: false
|
148
148
|
version_requirements: !ruby/object:Gem::Requirement
|
149
149
|
requirements:
|
150
150
|
- - "~>"
|
151
151
|
- !ruby/object:Gem::Version
|
152
|
-
version: 0.
|
152
|
+
version: 0.21.2
|
153
153
|
- !ruby/object:Gem::Dependency
|
154
154
|
name: rubocop
|
155
155
|
requirement: !ruby/object:Gem::Requirement
|
156
156
|
requirements:
|
157
157
|
- - "~>"
|
158
158
|
- !ruby/object:Gem::Version
|
159
|
-
version:
|
159
|
+
version: '1.3'
|
160
160
|
type: :development
|
161
161
|
prerelease: false
|
162
162
|
version_requirements: !ruby/object:Gem::Requirement
|
163
163
|
requirements:
|
164
164
|
- - "~>"
|
165
165
|
- !ruby/object:Gem::Version
|
166
|
-
version:
|
166
|
+
version: '1.3'
|
167
167
|
- !ruby/object:Gem::Dependency
|
168
168
|
name: rubocop-performance
|
169
169
|
requirement: !ruby/object:Gem::Requirement
|
@@ -184,14 +184,14 @@ dependencies:
|
|
184
184
|
requirements:
|
185
185
|
- - "~>"
|
186
186
|
- !ruby/object:Gem::Version
|
187
|
-
version: '
|
187
|
+
version: '2.0'
|
188
188
|
type: :development
|
189
189
|
prerelease: false
|
190
190
|
version_requirements: !ruby/object:Gem::Requirement
|
191
191
|
requirements:
|
192
192
|
- - "~>"
|
193
193
|
- !ruby/object:Gem::Version
|
194
|
-
version: '
|
194
|
+
version: '2.0'
|
195
195
|
description: |
|
196
196
|
Class helper for example files.
|
197
197
|
Usualy it's the alternative to environment variables (and `.env` files).
|
@@ -224,13 +224,16 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
224
224
|
- - ">="
|
225
225
|
- !ruby/object:Gem::Version
|
226
226
|
version: '2.5'
|
227
|
+
- - "<"
|
228
|
+
- !ruby/object:Gem::Version
|
229
|
+
version: '4'
|
227
230
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
228
231
|
requirements:
|
229
232
|
- - ">="
|
230
233
|
- !ruby/object:Gem::Version
|
231
234
|
version: '0'
|
232
235
|
requirements: []
|
233
|
-
rubygems_version: 3.1.
|
236
|
+
rubygems_version: 3.1.6
|
234
237
|
signing_key:
|
235
238
|
specification_version: 4
|
236
239
|
summary: Class helper for example files
|