Class: Pod::Command::Spec::Edit
- Inherits:
-
Pod::Command::Spec
- Object
- CLAide::Command
- Pod::Command
- Pod::Command::Spec
- Pod::Command::Spec::Edit
- Defined in:
- lib/cocoapods/command/spec.rb
Overview
———————————————————————–#
Class Method Summary collapse
Instance Method Summary collapse
- #exec_editor(*args) ⇒ Object
-
#initialize(argv) ⇒ Edit
constructor
A new instance of Edit.
- #run ⇒ Object
- #safe_exec(cmd, *args) ⇒ Object
- #validate! ⇒ Object
-
#which(cmd) ⇒ Object
Thank you homebrew.
- #which_editor ⇒ Object
Methods inherited from Pod::Command
Methods included from Pod::Config::Mixin
Constructor Details
#initialize(argv) ⇒ Edit
Returns a new instance of Edit.
203 204 205 206 207 208 |
# File 'lib/cocoapods/command/spec.rb', line 203 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
199 200 201 |
# File 'lib/cocoapods/command/spec.rb', line 199 def self. [["--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
251 252 253 254 |
# File 'lib/cocoapods/command/spec.rb', line 251 def exec_editor *args return if args.to_s.empty? safe_exec(which_editor, *args) end |
#run ⇒ Object
215 216 217 218 219 220 221 222 223 224 225 226 |
# File 'lib/cocoapods/command/spec.rb', line 215 def run filepath = if @show_all specs = get_path_of_spec(@spec, @show_all).split(/\n/) index = choose_from_array(specs, "Which spec would you like to edit [1-#{ specs.count }]? ") specs[index] else get_path_of_spec(@spec) end exec_editor(filepath.to_s) if File.exists? filepath raise Informative, "#{ filepath } doesn't exist." end |
#safe_exec(cmd, *args) ⇒ Object
256 257 258 259 260 |
# File 'lib/cocoapods/command/spec.rb', line 256 def safe_exec(cmd, *args) # This buys us proper argument quoting and evaluation # of environment variables in the cmd parameter. exec "/bin/sh", "-i", "-c", cmd + ' "$@"', "--", *args end |
#validate! ⇒ Object
210 211 212 213 |
# File 'lib/cocoapods/command/spec.rb', line 210 def validate! super help! "A podspec name is required." unless @spec end |
#which(cmd) ⇒ Object
Thank you homebrew
229 230 231 232 |
# File 'lib/cocoapods/command/spec.rb', line 229 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
234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 |
# File 'lib/cocoapods/command/spec.rb', line 234 def which_editor editor = ENV['EDITOR'] # If an editor wasn't set, try to pick a sane default return editor unless editor.nil? # Find Sublime Text 2 return 'subl' if which 'subl' # Find Textmate return 'mate' if which 'mate' # Find # BBEdit / TextWrangler return 'edit' if which 'edit' # Default to vim return 'vim' if which 'vim' raise Informative, "Failed to open editor. Set your 'EDITOR' environment variable." end |