Class: XCListen
- Inherits:
-
Object
- Object
- XCListen
- Defined in:
- lib/xclisten.rb,
lib/xclisten/version.rb,
lib/xclisten/shell_task.rb
Defined Under Namespace
Classes: ShellTask
Constant Summary collapse
- IOS_DEVICES =
{ 'iphone5s' => 'iPhone Retina (4-inch 64-bit)', 'iphone5' => 'iPhone Retina (4-inch)', 'iphone4' => 'iPhone Retina (3.5-inch)', 'ipad2' => 'iPad', 'ipad4' => 'iPad Retina', 'ipad_air' => 'iPad Retina (64-bit)' }
- VERSION =
"0.0.8"
Instance Attribute Summary collapse
-
#device ⇒ Object
readonly
Returns the value of attribute device.
-
#scheme ⇒ Object
readonly
Returns the value of attribute scheme.
-
#sdk ⇒ Object
readonly
Returns the value of attribute sdk.
-
#workspace ⇒ Object
readonly
Returns the value of attribute workspace.
Instance Method Summary collapse
- #can_run? ⇒ Boolean
-
#initialize(opts = {}) ⇒ XCListen
constructor
A new instance of XCListen.
- #install_pods ⇒ Object
- #listen ⇒ Object
- #project_name ⇒ Object
- #run_tests ⇒ Object
-
#validate_run ⇒ Object
TODO TEST THIS SPIKE.
- #workspace_path ⇒ Object
- #xcodebuild ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ XCListen
Returns a new instance of XCListen.
12 13 14 15 16 17 |
# File 'lib/xclisten.rb', line 12 def initialize(opts = {}) @scheme = opts[:scheme] || project_name @sdk = opts[:sdk] || 'iphonesimulator' @workspace = opts[:workspace] || workspace_path @device = IOS_DEVICES[opts[:device]] || IOS_DEVICES['iphone5s'] end |
Instance Attribute Details
#device ⇒ Object (readonly)
Returns the value of attribute device.
7 8 9 |
# File 'lib/xclisten.rb', line 7 def device @device end |
#scheme ⇒ Object (readonly)
Returns the value of attribute scheme.
8 9 10 |
# File 'lib/xclisten.rb', line 8 def scheme @scheme end |
#sdk ⇒ Object (readonly)
Returns the value of attribute sdk.
9 10 11 |
# File 'lib/xclisten.rb', line 9 def sdk @sdk end |
#workspace ⇒ Object (readonly)
Returns the value of attribute workspace.
10 11 12 |
# File 'lib/xclisten.rb', line 10 def workspace @workspace end |
Instance Method Details
#can_run? ⇒ Boolean
62 63 64 |
# File 'lib/xclisten.rb', line 62 def can_run? project_name && !project_name.empty? end |
#install_pods ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/xclisten.rb', line 42 def install_pods Dir.chdir(File.dirname(workspace)) do system 'pod install' puts 'Giving Xcode some time to index...' sleep 10 end end |
#listen ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/xclisten.rb', line 66 def listen validate_run puts "Started xclistening to #{workspace}" ignored = [/.git/, /.xc(odeproj|workspace|userdata|scheme|config)/, /.lock$/, /\.txt$/, /\.log$/] listener = Listen.to(Dir.pwd, :ignore => ignored) do |modified, added, removed| system 'clear' if modified.first =~ /Podfile$/ install_pods else run_tests end end listener.start sleep end |
#project_name ⇒ Object
32 33 34 |
# File 'lib/xclisten.rb', line 32 def project_name @project_name ||= File.basename(workspace_path, ".*") if workspace_path end |
#run_tests ⇒ Object
50 51 52 |
# File 'lib/xclisten.rb', line 50 def run_tests ShellTask.run("#{xcodebuild} test 2> xcodebuild_error.log | xcpretty -tc") end |
#validate_run ⇒ Object
TODO TEST THIS SPIKE
55 56 57 58 59 60 |
# File 'lib/xclisten.rb', line 55 def validate_run unless can_run? puts "[!] No xcworkspace found in this directory (or any child directories)" exit 1 end end |
#workspace_path ⇒ Object
28 29 30 |
# File 'lib/xclisten.rb', line 28 def workspace_path @workspace_path ||= Dir.glob("**/*.xcworkspace").sort_by(&:length).first end |
#xcodebuild ⇒ Object
36 37 38 39 40 |
# File 'lib/xclisten.rb', line 36 def xcodebuild cmd = "xcodebuild -workspace #{workspace} -scheme #{scheme} -sdk #{sdk}" cmd += " -destination 'name=#{device}'" unless @sdk == 'macosx' cmd end |