Class: Info
- Inherits:
-
Object
show all
- Defined in:
- lib/atk/info.rb
Overview
setting/getting values via an object (instead of opening/closing a file)
Defined Under Namespace
Classes: ReRaiseException, YamlFileDoesntExist
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize ⇒ Info
Returns a new instance of Info.
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
|
# File 'lib/atk/info.rb', line 115
def initialize()
begin
@path = Info.path
@folder = FS.dirname(@path)
rescue
raise YamlFileDoesntExist, " \n \n When calling Info.new\n I looked for an info.yaml in \#{Dir.pwd}\n (and I also looked in all of its parent folders)\n but I couldn't find an info.yaml file in any of them\n HEREDOC\n end\n # \n # open the yaml file\n # \n begin\n @data = YAML.load_file(@path)\n rescue => exception\n raise <<-HEREDOC.remove_indent\n \n When calling Info.new\n I found an info.yaml file\n however, when I tried to load it I received an error:\n \#{exception}\n HEREDOC\n end\n # \n # check the version, and parse accordingly\n # \n @version = nil\n begin\n @version = Version.new(@data['(using_atk_version)'].to_s)\n rescue => exception\n # if no version, then don't worry about parsing\n end\n\n if @version.is_a?(Version)\n begin\n if @version <= Version.new(\"1.0.0\")\n raise ReRaiseException, <<-HEREDOC.remove_indent\n \n So it looks like you're info.yaml file version is 1.0\n That was the alpha version of ATK, which is the only version that will not be supported\n \n \#{\"This is likely just an accident and the only thing that needs to be done is change:\".color_as :message}\n (using_atk_version): 1.0\n \#{\"to:\".color_as :message}\n (using_atk_version): 1.1.0\n HEREDOC\n elsif @version <= Version.new(\"1.1.0\")\n self.parser_version_1_1(@data)\n else\n # FUTURE: in the future do an online check to see if the latest ATK could handle this\n raise ReRaiseException, <<-HEREDOC.remove_indent\n \n Hey I think you need to update atk:\n `atk update`\n Why?\n The (using_atk_version) in the info.yaml is: \#{@version}\n However, I (your current version of ATK) don't know\n how to handle that version.\n HEREDOC\n end\n rescue ReRaiseException => exception\n raise exception\n rescue => exception\n raise <<-HEREDOC.remove_indent\n \n Original error message:\n \"\"\"\n \#{exception}\n \"\"\"\n \n This error is almost certainly not your fault\n It is likely a bug inside the atk_toolbox library\n Specifically the info.yaml parser\n \n If you agree and think this is a problem with the atk_toolbox library\n please go here:\n https://github.com/aggie-tool-kit/atk-toolbox/issues/new\n and tell us what happened before getting this message\n and also paste the original error message\n \n Sorry for the bug!\n HEREDOC\n end\n end\nend\n".remove_indent
|
Class Method Details
.[](element) ⇒ Object
311
312
313
|
# File 'lib/atk/info.rb', line 311
def self.[](element)
return (Info.new)[element]
end
|
.commands ⇒ Object
327
328
329
|
# File 'lib/atk/info.rb', line 327
def self.commands
return (Info.new).commands
end
|
.data ⇒ Object
319
320
321
|
# File 'lib/atk/info.rb', line 319
def self.data
return (Info.new).data
end
|
.folder ⇒ Object
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
|
# File 'lib/atk/info.rb', line 212
def self.folder()
folder = FileSystem.join(Dir.pwd, "")
loop do
if FileSystem.file?( FileSystem.join(folder, "info.yaml"))
return folder
end
next_location = File.dirname(folder)
if next_location == folder
raise " \n \#{\"Couldn't find an info.yaml in the current directory or any parent directory\".color_as(:bad)}\n \#{Dir.pwd}\n Are you sure you're running the command from the correct directory?\n HEREDOC\n end\n \n folder = next_location\n end\nend\n".remove_indent
|
.init ⇒ Object
294
295
296
297
298
299
300
301
302
303
304
|
# File 'lib/atk/info.rb', line 294
def self.init
current_dir = Dir.pwd/"info.yaml"
if not File.file?(current_dir)
FileUtils.cp(__dir__/"default_info.yaml", current_dir)
puts "info.yaml created successfully"
else
puts "There appears to already be an info.yaml file\nThe init method is not yet able to merge the ATK init data with the current data\n(this will be fixed in the future)"
end
end
|
.path ⇒ Object
239
240
241
|
# File 'lib/atk/info.rb', line 239
def self.path()
return FileSystem.join( self.folder(), "info.yaml")
end
|
.paths ⇒ Object
335
336
337
|
# File 'lib/atk/info.rb', line 335
def self.paths
return (Info.new).paths
end
|
.version ⇒ Object
246
247
248
|
# File 'lib/atk/info.rb', line 246
def self.version()
return (Info.new).version
end
|
Instance Method Details
#[](element) ⇒ Object
307
308
309
|
# File 'lib/atk/info.rb', line 307
def [](element)
return @data[element]
end
|
#commands ⇒ Object
324
325
326
|
# File 'lib/atk/info.rb', line 324
def commands
return @commands || {}
end
|
#data ⇒ Object
316
317
318
|
# File 'lib/atk/info.rb', line 316
def data
return @data
end
|
#folder ⇒ Object
209
210
211
|
# File 'lib/atk/info.rb', line 209
def folder()
return @folder
end
|
#parser_version_1_1(data) ⇒ Object
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
|
# File 'lib/atk/info.rb', line 250
def parser_version_1_1(data)
begin
@commands = data['(project)']['(commands)']
if !(@commands.is_a?(Hash))
@commands = {}
end
rescue
@commands = {}
end
begin
@paths = data['(project)']['(paths)']
if !(@paths.is_a?(Hash))
@paths = {}
end
rescue
@paths = {}
end
@root = FileSystem.dirname(@path)
for each_key, each_value in @paths
if each_value.is_a?(Array)
each_value = FileSystem.join(*each_value)
end
if each_value.is_a?(String)
if each_value =~ /\A\.\//
each_value = each_value[2..-1]
end
if not each_value.size > 0 && each_value[0] == '/'
@paths[each_key] = FileSystem.join(@root, each_value)
end
end
end
end
|
#path ⇒ Object
236
237
238
|
# File 'lib/atk/info.rb', line 236
def path()
return @path
end
|
#paths ⇒ Object
332
333
334
|
# File 'lib/atk/info.rb', line 332
def paths
return @paths || {}
end
|
#version ⇒ Object
243
244
245
|
# File 'lib/atk/info.rb', line 243
def version()
return @version
end
|