Class: Pod::Command::Spec::Edit
Overview
———————————————————————–#
Class Method Summary
collapse
Instance Method Summary
collapse
parse, report_error, run, verify_git_version!
#config
Constructor Details
#initialize(argv) ⇒ Edit
Returns a new instance of Edit.
245
246
247
248
249
250
|
# File 'lib/cocoapods/command/spec.rb', line 245
def initialize(argv)
@show_all = argv.flag?('show-all')
@spec = argv.shift_argument
@spec = @spec.gsub('.podspec', '') unless @spec.nil?
super
end
|
Class Method Details
.options ⇒ Object
240
241
242
243
|
# File 'lib/cocoapods/command/spec.rb', line 240
def self.options
[['--show-all', 'Pick which spec to edit from all available' \
'versions of the given podspec']].concat(super)
end
|
Instance Method Details
#exec_editor(*args) ⇒ Object
294
295
296
297
|
# File 'lib/cocoapods/command/spec.rb', line 294
def exec_editor(*args)
return if args.to_s.empty?
safe_exec(which_editor, *args)
end
|
#run ⇒ Object
257
258
259
260
261
262
263
264
265
266
267
268
269
|
# File 'lib/cocoapods/command/spec.rb', line 257
def run
if @show_all
specs = get_path_of_spec(@spec, @show_all).split(/\n/)
message = "Which spec would you like to edit [1-#{specs.count}]? "
index = choose_from_array(specs, message)
filepath = specs[index]
else
filepath = get_path_of_spec(@spec)
end
exec_editor(filepath.to_s) if File.exist? filepath
raise Informative, "#{ filepath } doesn't exist."
end
|
#safe_exec(cmd, *args) ⇒ Object
299
300
301
302
303
|
# File 'lib/cocoapods/command/spec.rb', line 299
def safe_exec(cmd, *args)
exec('/bin/sh', '-i', '-c', cmd + ' "$@"', '--', *args)
end
|
#validate! ⇒ Object
252
253
254
255
|
# File 'lib/cocoapods/command/spec.rb', line 252
def validate!
super
help! 'A podspec name is required.' unless @spec
end
|
#which(cmd) ⇒ Object
272
273
274
275
|
# File 'lib/cocoapods/command/spec.rb', line 272
def which(cmd)
dir = ENV['PATH'].split(':').find { |p| File.executable? File.join(p, cmd) }
Pathname.new(File.join(dir, cmd)) unless dir.nil?
end
|
#which_editor ⇒ Object
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
|
# File 'lib/cocoapods/command/spec.rb', line 277
def which_editor
editor = ENV['EDITOR']
return editor unless editor.nil?
return 'subl' if which 'subl'
return 'mate' if which 'mate'
return 'edit' if which 'edit'
return 'vim' if which 'vim'
raise Informative, "Failed to open editor. Set your 'EDITOR' environment variable."
end
|