wielder_of_anor 0.2.2 → 0.3.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
  SHA1:
3
- metadata.gz: 090d66633dff2b9e498891c7e6d9489e246916b4
4
- data.tar.gz: fcc8ccb38e9922feaad5a64ec8d4644c2336984e
3
+ metadata.gz: 67aeb5b09bfba58a5a26a768a35d35cb9bae1cd6
4
+ data.tar.gz: 6808e6fa94ec66058aceacbbae676c4f0a1e46a7
5
5
  SHA512:
6
- metadata.gz: a0f729c87f2271421ab419a617c007be6b814a82df2144b2b104d6b330822797bba33f4ea9b85c42e389c2ab0a4d96b04620fd58218fd876554eeefe487bd68b
7
- data.tar.gz: 30d630f1a1f4842d9519cb54dc1dae53412e08d87906835f169520edbfa450f93fc76777d6e7647603f477a024fbd93693fd065ea1da40a33f6a45c51b04cb75
6
+ metadata.gz: e2e49996bf345071b50f14226d38b80b50c996817afc35ad1b23969c142c35a9e60de09ab9f94d0609a12876ee9118b862a0ed3ad85f7c59dc9d7555d7133548
7
+ data.tar.gz: b65fa2f77f4f67e7a61f3beecbda5a0c1e90dc54c16754ded3739eddf69265981bafcdad1b3757df7f9f396a5a7960907d6843d56bb58bd75e4a9bd755a68ed1
@@ -1,9 +1,14 @@
1
1
  require 'shellwords'
2
2
  require 'yaml'
3
3
  require 'rainbow'
4
+ require 'fileutils'
5
+
6
+ require_relative 'wielder_of_anor/version'
4
7
 
5
8
  module WielderOfAnor
6
9
  class WielderOfAnor
10
+ include WielderOfAnorVersion
11
+
7
12
  def initialize
8
13
  set_app_directory
9
14
 
@@ -24,8 +29,9 @@ module WielderOfAnor
24
29
  ##############################################################################
25
30
 
26
31
  def prepare(commit_message, force_commit)
27
- set_app_directory
28
-
32
+ # If there's just one, it's the current version. Don't run if the current config is present.
33
+ restore_settings if Dir.glob("#{@app_directory.chomp("/wielder_of_anor-#{VERSION}")}/wielder_of_anor*").length > 1 &&
34
+ !(File.exists?("#{@app_directory}/lib/config.yaml"))
29
35
  first_run unless File.exists?("#{@app_directory}/lib/config.yaml")
30
36
 
31
37
  config = YAML.load_file("#{@app_directory}/lib/config.yaml")
@@ -41,8 +47,7 @@ module WielderOfAnor
41
47
  git_diff
42
48
 
43
49
  @files_changed_file = File.open(@files_changed_file_location, "r")
44
-
45
- get_forbidden_words(config['forbidden_words_file_location'])
50
+ @forbidden_words = config['forbidden_words']
46
51
  end
47
52
 
48
53
  def help
@@ -72,20 +77,18 @@ module WielderOfAnor
72
77
  set_app_directory
73
78
  config = YAML.load_file("#{@app_directory}/lib/config.yaml")
74
79
 
75
- unless config
80
+ unless config && config['forbidden_words']
76
81
  lines_pretty_print Rainbow('You have yet to set your forbidden words! Please run the app with the parameter '\
77
82
  '\'config\' to set up your configurations and forbidden words.').red
78
83
 
79
84
  abort
80
85
  end
81
86
 
82
- get_forbidden_words(config['forbidden_words_file_location'])
83
-
84
87
  lines_pretty_print Rainbow('Your forbidden words are:').yellow
85
88
 
86
89
  single_space
87
90
 
88
- @forbidden_words.each do |word|
91
+ config['forbidden_words'].each do |word|
89
92
  lines_pretty_print Rainbow(word).yellow
90
93
  end
91
94
 
@@ -94,51 +97,58 @@ module WielderOfAnor
94
97
  abort
95
98
  end
96
99
 
97
- def first_run
98
- lines_pretty_print 'Thanks for downloading Wielder of Anor! Let\'s run through the '\
99
- 'initial setup!'
100
- lines_pretty_print Rainbow('**Please ensure your file locations are correct. Wielder of Anor '\
101
- 'does not currently check your input for validity.**').red
100
+ # Attempt to restore settings from previous version.
101
+ def restore_settings
102
+ lines_pretty_print 'I see that I\'ve been recently updated.'
103
+ lines_pretty_print Rainbow('Would you like to restore the settings from the previous installation?').yellow
102
104
 
103
- STDIN.gets
105
+ answered = false
104
106
 
105
- files_changed_file_location = set_files_changed_file_location
107
+ until answered
108
+ answer = STDIN.gets.strip!
106
109
 
107
- forbidden_words_file_location = set_forbidden_words_file_location
110
+ single_space
108
111
 
109
- commit_for_user = set_commit_for_user
112
+ if answer == 'yes' || answer == 'y' || answer == 'no' || answer == 'n'
113
+ answered = true
114
+ else
115
+ lines_pretty_print Rainbow('Please input either \'yes\' or \'no\'.').yellow
116
+ end
117
+ end
118
+
119
+ return if answer == 'no' || answer == 'n'
120
+
121
+ lines_pretty_print 'One moment, please.'
110
122
 
111
123
  single_space
112
124
 
113
- set_configs(files_changed_file_location, forbidden_words_file_location, commit_for_user)
125
+ all_gems = Dir.glob("#{@app_directory.chomp("/wielder_of_anor-#{VERSION}")}/wielder_of_anor*")
126
+
127
+ # glob orders things in the array alphabetically, so the second-to-last one in the array is the
128
+ # most recent version that is not the current version.
129
+ previous_config_file = "#{all_gems[-2]}/lib/config.yaml"
130
+ FileUtils.copy_file(previous_config_file, "#{@app_directory}/lib/config.yaml")
131
+
132
+ lines_pretty_print 'Done! Please run me again when you\'re ready.'
114
133
 
115
- set_forbidden_words(forbidden_words_file_location)
134
+ abort
116
135
  end
117
136
 
118
- def set_files_changed_file_location
119
- set_app_directory
137
+ def first_run
138
+ lines_pretty_print 'Thanks for downloading Wielder of Anor! Let\'s run through the '\
139
+ 'initial setup!'
140
+
141
+ STDIN.gets
120
142
 
121
- lines_pretty_print 'Whenever you run Wielder of Anor, it will first run a git diff and '\
122
- 'export the results to a file (so that it\'s only checking the files '\
123
- 'you have actually changed and not your entire code base!). Where '\
124
- 'would you like that file to be located?'
125
- lines_pretty_print Rainbow('(Just hit enter to accept the default, which is'\
126
- " #{@app_directory}/lib/files_changed.)").yellow
127
- files_changed_file_location = STDIN.gets.strip!
128
- files_changed_file_location = "#{@app_directory}/lib/files_changed" if files_changed_file_location == ''
143
+ files_changed_file_location = "#{@app_directory}/lib/files_changed"
129
144
 
130
- files_changed_file_location
131
- end
145
+ commit_for_user = set_commit_for_user
132
146
 
133
- def set_forbidden_words_file_location
134
- lines_pretty_print 'Your \'forbidden words\' are stored in a file. Where would like that'\
135
- ' file to be located?'
136
- lines_pretty_print Rainbow('(Just hit enter to accept the default, which is'\
137
- " #{@app_directory}/lib/forbidden_words.)").yellow
138
- forbidden_words_file_location = STDIN.gets.strip!
139
- forbidden_words_file_location = "#{@app_directory}/lib/forbidden_words" if forbidden_words_file_location == ""
147
+ single_space
140
148
 
141
- forbidden_words_file_location
149
+ forbidden_words = set_forbidden_words
150
+
151
+ set_configs(files_changed_file_location, forbidden_words, commit_for_user)
142
152
  end
143
153
 
144
154
  def set_commit_for_user
@@ -157,25 +167,30 @@ module WielderOfAnor
157
167
  commit_for_user
158
168
  end
159
169
 
160
- def set_configs(files_changed_file_location, forbidden_words_file_location, commit_for_user)
170
+ def set_configs(files_changed_file_location, forbidden_words, commit_for_user)
161
171
  config = {}
162
172
  config['files_changed_file_location'] = files_changed_file_location
163
- config['forbidden_words_file_location'] = forbidden_words_file_location
164
173
 
165
174
  if commit_for_user == 'yes' || commit_for_user == 'y'
166
175
  config['commit_for_user'] = true
167
- elsif commit_for_user == 'no' || commit_for_user == 'n'
176
+ else
168
177
  config['commit_for_user'] = false
169
178
  end
170
179
 
180
+ config['forbidden_words'] = forbidden_words
181
+
171
182
  file = File.open("#{@app_directory}/lib/config.yaml", 'w')
172
183
  YAML.dump(config, file)
173
184
  file.close
185
+
186
+ lines_pretty_print 'And with that, we\'re done! Feel free to run Wielder of Anor again if'\
187
+ ' you\'d like to check your code now!'
188
+
189
+ abort
174
190
  end
175
191
 
176
- def set_forbidden_words(forbidden_words_file_location)
177
- forbidden_words_file = File.open(forbidden_words_file_location, 'w')
178
- forbidden_words_count = 0
192
+ def set_forbidden_words
193
+ forbidden_words = []
179
194
 
180
195
  done = false
181
196
 
@@ -185,48 +200,32 @@ module WielderOfAnor
185
200
 
186
201
  until done do
187
202
  lines_pretty_print Rainbow('Enter a forbidden word and hit enter. If you are done entering '\
188
- 'forbidden words, type \'x211\' and hit enter instead.').yellow unless forbidden_words_count > 0
203
+ 'forbidden words, type \'x211\' and hit enter instead.').yellow unless forbidden_words.count > 0
189
204
 
190
205
  lines_pretty_print Rainbow('Added! Enter another forbidden word and hit enter. If you are done '\
191
- 'entering forbidden words, type \'x211\' and hit enter instead.').yellow unless forbidden_words_count == 0
206
+ 'entering forbidden words, type \'x211\' and hit enter instead.').yellow unless forbidden_words.count == 0
192
207
  word = STDIN.gets.strip!
208
+
193
209
  single_space
194
210
 
195
211
  if word == 'x211'
196
212
  done = true
197
213
  else
198
- forbidden_words_file.puts word
199
- forbidden_words_count += 1
214
+ forbidden_words << word
200
215
  end
201
216
  end
202
217
 
203
- forbidden_words_file.close
204
-
205
- lines_pretty_print 'And with that, we\'re done! Feel free to run Wielder of Anor again if'\
206
- ' you\'d like to check your code now!'
207
-
208
- abort
218
+ forbidden_words
209
219
  end
210
220
 
211
221
  def git_diff
212
222
  bash("git diff HEAD --name-only --staged > #{@files_changed_file_location}")
213
223
  end
214
224
 
215
- def get_forbidden_words(file_location)
216
- forbidden_words_file = File.open(file_location)
217
-
218
- forbidden_words_file.each_line do |line|
219
- @forbidden_words << line.strip
220
- end
221
-
222
- forbidden_words_file.close
223
- end
224
-
225
225
  def add_forbidden_word(word)
226
226
  set_app_directory
227
- config = YAML.load_file("#{@app_directory}/lib/config.yaml")
228
- forbidden_words_file = File.open(config['forbidden_words_file_location'], 'a')
229
- get_forbidden_words(config['forbidden_words_file_location'])
227
+ config_yaml = YAML.load_file("#{@app_directory}/lib/config.yaml")
228
+ config_file = File.open("#{@app_directory}/lib/config.yaml", 'w')
230
229
 
231
230
  if word.nil?
232
231
  lines_pretty_print Rainbow('Please submit your word as a second parameter.').red
@@ -234,14 +233,15 @@ module WielderOfAnor
234
233
  abort
235
234
  end
236
235
 
237
- if @forbidden_words.include?(word)
236
+ if config_yaml['forbidden_words'].include?(word)
238
237
  lines_pretty_print Rainbow("''#{word}'' is already a forbidden word!").red
239
238
 
240
239
  abort
241
240
  end
242
241
 
243
- forbidden_words_file.puts word
244
- forbidden_words_file.close
242
+ config_yaml['forbidden_words'] << word
243
+
244
+ YAML.dump(config_yaml, config_file)
245
245
 
246
246
  lines_pretty_print 'Added!'
247
247
 
@@ -1,3 +1,3 @@
1
- module WielderOfAnor
2
- VERSION = "0.2.2"
1
+ module WielderOfAnorVersion
2
+ VERSION = "0.3.0"
3
3
  end
@@ -5,7 +5,7 @@ require 'wielder_of_anor/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = 'wielder_of_anor'
8
- spec.version = WielderOfAnor::VERSION
8
+ spec.version = WielderOfAnorVersion::VERSION
9
9
  spec.authors = ['Chris Sellek']
10
10
  spec.email = ['iamsellek@gmail.com']
11
11
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wielder_of_anor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Sellek
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-05-26 00:00:00.000000000 Z
11
+ date: 2016-06-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rainbow