Class: Chairs::Musician
- Inherits:
-
Object
- Object
- Chairs::Musician
- Defined in:
- lib/musician.rb
Instance Method Summary collapse
- #clean ⇒ Object
- #help ⇒ Object
-
#initialize(args) ⇒ Musician
constructor
A new instance of Musician.
- #list ⇒ Object
- #open ⇒ Object
- #pull ⇒ Object
- #push ⇒ Object
- #rm ⇒ Object
- #sync ⇒ Object
Constructor Details
#initialize(args) ⇒ Musician
Returns a new instance of Musician.
13 14 15 16 17 18 |
# File 'lib/musician.rb', line 13 def initialize(args) # find a command @params = args command = @params[0].to_sym rescue :help commands.include?(command) ? send(command.to_sym) : help end |
Instance Method Details
#clean ⇒ Object
140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/musician.rb', line 140 def clean setup puts "Deleting App directory" target_path = Pow(@app_folder).to_s.gsub(" ", "\\ ") command = "rm -r #{target_path}" puts command system command puts "Cleaned" end |
#help ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/musician.rb', line 20 def help puts "" puts "Musical Chairs - for swapping in/out app data in the iOS Simulator." puts "" puts " sync takes the app from the *currently open* sim, and send it to all other sims." puts " pull [name] get documents and support files from latest built app and store as name." puts " push [name] overwrite documents and support files from the latest build in Xcode." puts " rm [name] delete the files for the chair." puts " open open the current app folder in Finder." puts " list list all the current docs in working directory." puts "" puts " ./" end |
#list ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/musician.rb', line 94 def list unless Pow("chairs/").exists? puts "You haven't used chairs yet." return end # get all folders in the directory folders = [] @target_folder = @params[1] Pow("chairs/").each do |doc| if doc.directory? filename = File.basename(doc) size = `du -sh '#{doc}' | cut -f1`.strip folders << "#{filename} (#{size})" end end # turn it into a sentence if folders.length == 0 folders = "have no chairs setup." elsif folders.length == 1 folders = "just " + folders[0] else last = folders.last folders = "have " + folders[0..-2].join(", ") + " and " + last end puts "Currently you #{ folders }." end |
#open ⇒ Object
34 35 36 37 38 |
# File 'lib/musician.rb', line 34 def open setup puts "Opening #{ @app_name }" `open "#{ @app_folder }"` end |
#pull ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/musician.rb', line 40 def pull unless @params[1] puts "Chairs needs a name for the target." return end setup # validate if Pow("chairs/#{@target_folder}").exists? print "This chair already exists, do you want to overwrite? [Yn] " confirm = STDIN.gets.chomp if confirm.downcase == "y" || confirm == "" FileUtils.rm_r( Pow().to_s + "/chairs/#{@target_folder}/") else return end end puts "Pulling files for #{ @app_name }" puts "From #{@app_folder} to chairs/#{@target_folder}" Pow("chairs/#{@target_folder}/").create_directory do copy(Pow("#{@app_folder}/*"), Pow()) end puts "Done!" end |
#push ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/musician.rb', line 69 def push unless @params[1] puts "Chairs needs a name for the target." return end setup unless Pow("chairs/#{@target_folder}").exists? puts "You don't have a folder for #{@target_folder}." list return end puts "Pushing files for #{@app_name}" puts "From chairs/#{@target_folder} to #{@app_folder}" # clean the directory we're about to throw things in target_path = Pow(@app_folder).to_s.gsub(" ", "\\ ") system "rm -r #{target_path}/*" copy(Pow("chairs/#{@target_folder}/*"), Pow("#{@app_folder}/")) puts "Done!" end |
#rm ⇒ Object
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/musician.rb', line 124 def rm unless @params[1] puts "Chairs needs a name for the target." return end @target_folder = @params[1] if Pow("chairs/#{@target_folder}/").exists? FileUtils.rm_r( Pow().to_s + "/chairs/#{@target_folder}/") puts "Deleted #{@target_folder}/" else puts "That chair does not exist." list end end |
#sync ⇒ Object
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 |
# File 'lib/musician.rb', line 153 def sync setup simctl = SimctlParser.new current_device = simctl.open_device get_devices = simctl.get_devices unless current_device puts "Couldn't find an active iOS Simulator" return end print "Migrating #{@app_name} from #{current_device[:name]} to all other devices" os = "" get_devices.each do |device| next if device[:id] == current_device[:id] if device[:os] != os os = device[:os] print "\n #{os} -> " end new_folder = "~/Library/Developer/CoreSimulator/Devices/" + device[:id] + "/data/Applications" copy(@app_folder, new_folder, false) print "#{ device[:name] }, " end end |