Skip to content

Commit

Permalink
Merge pull request #5 from hyperoslo/refactor/make-it-perfect
Browse files Browse the repository at this point in the history
Refactor: make it perfect
  • Loading branch information
zenangst committed Nov 13, 2015
2 parents 5cf552a + 83b7629 commit dcda921
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 17 deletions.
14 changes: 6 additions & 8 deletions Pod/Pod.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,17 @@
objects = {

/* Begin PBXBuildFile section */
BD6929341BC528C60063E97E /* TestCompass.swift in Sources */ = {isa = PBXBuildFile; fileRef = BD6929331BC528C60063E97E /* TestCompass.swift */; settings = {ASSET_TAGS = (); }; };
BD93420C1BC4FCF200F25395 /* Compass.swift in Sources */ = {isa = PBXBuildFile; fileRef = BD93420B1BC4FCF200F25395 /* Compass.swift */; settings = {ASSET_TAGS = (); }; };
BD6929341BC528C60063E97E /* TestCompass.swift in Sources */ = {isa = PBXBuildFile; fileRef = BD6929331BC528C60063E97E /* TestCompass.swift */; };
BD93420C1BC4FCF200F25395 /* Compass.swift in Sources */ = {isa = PBXBuildFile; fileRef = BD93420B1BC4FCF200F25395 /* Compass.swift */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
146D72AC1AB782920058798C /* Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = Tests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
146D72B11AB782920058798C /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
14A139B21AEFC72B00AD732F /* Tests-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Tests-Bridging-Header.h"; sourceTree = "<group>"; };
14C136511AB784B200B7B07A /* .travis.yml */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = .travis.yml; path = ../.travis.yml; sourceTree = "<group>"; };
14C136521AB784B200B7B07A /* CONTRIBUTING.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; name = CONTRIBUTING.md; path = ../CONTRIBUTING.md; sourceTree = "<group>"; };
14C136541AB784B200B7B07A /* LICENSE.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; name = LICENSE.md; path = ../LICENSE.md; sourceTree = "<group>"; };
14C136551AB784B200B7B07A /* README.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; name = README.md; path = ../README.md; sourceTree = "<group>"; };
14C1365C1AB784BC00B7B07A /* .gitkeep */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = .gitkeep; sourceTree = "<group>"; };
BD6929331BC528C60063E97E /* TestCompass.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestCompass.swift; sourceTree = "<group>"; };
BD93420B1BC4FCF200F25395 /* Compass.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Compass.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */
Expand Down Expand Up @@ -59,7 +57,6 @@
isa = PBXGroup;
children = (
146D72B01AB782920058798C /* Supporting Files */,
14A139B21AEFC72B00AD732F /* Tests-Bridging-Header.h */,
BD6929331BC528C60063E97E /* TestCompass.swift */,
);
path = Tests;
Expand Down Expand Up @@ -87,7 +84,6 @@
14C1365B1AB784BC00B7B07A /* Source */ = {
isa = PBXGroup;
children = (
14C1365C1AB784BC00B7B07A /* .gitkeep */,
BD93420B1BC4FCF200F25395 /* Compass.swift */,
);
name = Source;
Expand Down Expand Up @@ -261,7 +257,8 @@
INFOPLIST_FILE = Tests/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "Tests/Tests-Bridging-Header.h";
SWIFT_INSTALL_OBJC_HEADER = NO;
SWIFT_OBJC_BRIDGING_HEADER = "";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
};
name = Debug;
Expand All @@ -277,7 +274,8 @@
INFOPLIST_FILE = Tests/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "Tests/Tests-Bridging-Header.h";
SWIFT_INSTALL_OBJC_HEADER = NO;
SWIFT_OBJC_BRIDGING_HEADER = "";
};
name = Release;
};
Expand Down
1 change: 0 additions & 1 deletion Pod/Tests/TestCompass.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,4 @@ class TestCompass: XCTestCase {
XCTAssert(arguments.isEmpty)
}
}

}
4 changes: 0 additions & 4 deletions Pod/Tests/Tests-Bridging-Header.h

This file was deleted.

Empty file removed Source/.gitkeep
Empty file.
18 changes: 14 additions & 4 deletions Source/Compass.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,18 @@ import UIKit
public struct Compass {

private static var internalScheme = ""

public static var scheme: String {
set { Compass.internalScheme = newValue }
get { return "\(Compass.internalScheme)://" }
}

public static var routes = [String]()

public static func parse(url: NSURL, completion: (route: String, arguments: [String : String]) -> Void) -> Bool {
public typealias ParseCompletion = (route: String, arguments: [String : String]) -> Void

public static func parse(url: NSURL, completion: ParseCompletion) -> Bool {
var result = false
let query = url.absoluteString.substringFromIndex(scheme.endIndex)

for route in routes.sort({ $0 < $1 }) {
Expand All @@ -19,7 +23,7 @@ public struct Compass {
.map(String.init))
.first else { continue }

if (query.hasPrefix(prefix) || prefix.hasPrefix(query)) {
if query.hasPrefix(prefix) || prefix.hasPrefix(query) {
let queryString = query.stringByReplacingOccurrencesOfString(prefix, withString: "")
let queryArguments = paths(queryString)
let routeArguments = paths(route).filter { $0.containsString("{") }
Expand All @@ -32,19 +36,25 @@ public struct Compass {
? queryArguments[index] : nil
}
completion(route: route, arguments: arguments)
return true

result = true
break
}
}
}
return false

return result
}

public static func navigate(urn: String, scheme: String = Compass.scheme) {
let stringURL = "\(scheme)\(urn)"
guard let url = NSURL(string: stringURL) else { return }

UIApplication.sharedApplication().openURL(url)
}

// MARK: - Private Helpers

private static func paths(urn: String) -> [String] {
return urn.characters
.split { $0 == ":" }
Expand Down

0 comments on commit dcda921

Please sign in to comment.