Skip to content

Commit

Permalink
Refactor code
Browse files Browse the repository at this point in the history
  • Loading branch information
vadymmarkov committed Sep 27, 2016
1 parent b966ed9 commit 65f8afb
Show file tree
Hide file tree
Showing 23 changed files with 153 additions and 134 deletions.
4 changes: 2 additions & 2 deletions Cartfile.private
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
github "Quick/Quick" "v0.9.2"
github "Quick/Nimble" "v4.0.0"
github "Quick/Quick"
github "Quick/Nimble"
4 changes: 2 additions & 2 deletions Cartfile.resolved
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
github "Quick/Nimble" "v4.0.0"
github "Quick/Quick" "v0.9.2"
github "Quick/Nimble" "v5.0.0"
github "Quick/Quick" "v0.10.0"
15 changes: 12 additions & 3 deletions Fakery.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0730;
LastUpgradeCheck = 0710;
LastUpgradeCheck = 0800;
ORGANIZATIONNAME = "Vadym Markov";
TargetAttributes = {
BC827FA71BFA3CE1005F09A4 = {
Expand Down Expand Up @@ -917,7 +917,7 @@
BC827FB91BFA3CE1005F09A4 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
CODE_SIGN_IDENTITY = "-";
CODE_SIGN_IDENTITY = "";
COMBINE_HIDPI_IMAGES = YES;
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
Expand All @@ -940,7 +940,7 @@
BC827FBA1BFA3CE1005F09A4 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
CODE_SIGN_IDENTITY = "-";
CODE_SIGN_IDENTITY = "";
COMBINE_HIDPI_IMAGES = YES;
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
Expand Down Expand Up @@ -1005,8 +1005,10 @@
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
Expand Down Expand Up @@ -1054,8 +1056,10 @@
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
Expand All @@ -1076,6 +1080,7 @@
MACOSX_DEPLOYMENT_TARGET = 10.10;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
TARGETED_DEVICE_FAMILY = "1,2";
VALIDATE_PRODUCT = YES;
VERSIONING_SYSTEM = "apple-generic";
Expand All @@ -1086,6 +1091,7 @@
BCF0DF4F1BF9F77E00427DB4 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "";
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
Expand All @@ -1103,6 +1109,7 @@
BCF0DF501BF9F77E00427DB4 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "";
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
Expand Down Expand Up @@ -1143,6 +1150,7 @@
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ANALYZER_NONNULL = YES;
"CODE_SIGN_IDENTITY[sdk=appletvos*]" = "";
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
Expand All @@ -1164,6 +1172,7 @@
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ANALYZER_NONNULL = YES;
"CODE_SIGN_IDENTITY[sdk=appletvos*]" = "";
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0730"
LastUpgradeVersion = "0800"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0730"
LastUpgradeVersion = "0800"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0730"
LastUpgradeVersion = "0800"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
23 changes: 15 additions & 8 deletions Source/Data/Parser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public final class Parser {
}
}

var data = [String: AnyObject]()
var data = [String: Any]()
var provider: Provider

public init(locale: String = Config.defaultLocale) {
Expand Down Expand Up @@ -43,19 +43,26 @@ public final class Parser {
return parsed
}

public func fetchRaw(_ key: String) -> AnyObject? {
public func fetchRaw(_ key: String) -> Any? {
let parts = key.components(separatedBy: ".")

guard let localeData = data[locale], var parsed = localeData["faker"] , !parts.isEmpty else {
return nil
}
guard let localeData = data[locale] as? [String: Any],
var parsed = localeData["faker"] as? [String: Any],
!parts.isEmpty else { return nil }

var result: Any?

for part in parts {
guard let parsedPart = parsed?[part] else { continue }
guard let parsedPart = parsed[part] as? [String: Any] else {
result = parsed[part]
continue
}

parsed = parsedPart
result = parsedPart
}

return parsed as AnyObject?
return result
}

func parse(_ template: String, forSubject subject: String) -> String {
Expand Down Expand Up @@ -124,7 +131,7 @@ public final class Parser {
func loadData() {
guard let localeData = provider.dataForLocale(locale),
let parsedData = try? JSONSerialization.jsonObject(with: localeData, options: .allowFragments),
let json = parsedData as? [String: AnyObject] else {
let json = parsedData as? [String: Any] else {
if locale != Config.defaultLocale {
locale = Config.defaultLocale
} else {
Expand Down
8 changes: 5 additions & 3 deletions Source/Data/Provider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@ public final class Provider {
}


if let path = path,
let fileURL: URL = URL(fileURLWithPath: path),
let data = try? Data(contentsOf: fileURL){
if let path = path {
let fileURL = URL(fileURLWithPath: path)

if let data = try? Data(contentsOf: fileURL) {
translation = data
translations[locale] = data
}
}
}

Expand Down
26 changes: 13 additions & 13 deletions Source/Faker.swift
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
open class Faker {
public final class Faker {

open var locale: String {
public var locale: String {
didSet {
if locale != oldValue {
parser.locale = locale
}
}
}

open let address: Address
open let app: App
open let business: Business
open let company: Company
open let commerce: Commerce
open let internet: Internet
open let lorem: Lorem
open let name: Name
open let phoneNumber: PhoneNumber
open let team: Team
open let number: Number
public let address: Address
public let app: App
public let business: Business
public let company: Company
public let commerce: Commerce
public let internet: Internet
public let lorem: Lorem
public let name: Name
public let phoneNumber: PhoneNumber
public let team: Team
public let number: Number

let parser: Parser

Expand Down
36 changes: 18 additions & 18 deletions Source/Generators/Address.swift
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import Foundation

open class Address: Generator {
public final class Address: Generator {

open func city() -> String {
public func city() -> String {
return generate("address.city")
}

open func streetName() -> String {
public func streetName() -> String {
return generate("address.street_name")
}

open func secondaryAddress() -> String {
public func secondaryAddress() -> String {
return numerify(generate("address.secondary_address"))
}

open func streetAddress(includeSecondary: Bool = false) -> String {
public func streetAddress(includeSecondary: Bool = false) -> String {
var streetAddress = numerify(generate("address.street_address"))

if includeSecondary {
Expand All @@ -24,59 +24,59 @@ open class Address: Generator {
return streetAddress
}

open func buildingNumber() -> String {
public func buildingNumber() -> String {
return bothify(generate("address.building_number"))
}

open func postcode(stateAbbreviation: String = "") -> String {
public func postcode(stateAbbreviation: String = "") -> String {
if stateAbbreviation.isEmpty {
return bothify(generate("address.postcode"))
}

return bothify(generate("address.postcode_by_state.\(stateAbbreviation)"))
}

open func timeZone() -> String {
public func timeZone() -> String {
return generate("address.time_zone")
}

open func streetSuffix() -> String {
public func streetSuffix() -> String {
return generate("address.street_suffix")
}

open func citySuffix() -> String {
public func citySuffix() -> String {
return generate("address.city_suffix")
}

open func cityPrefix() -> String {
public func cityPrefix() -> String {
return generate("address.city_prefix")
}

open func stateAbbreviation() -> String {
public func stateAbbreviation() -> String {
return generate("address.state_abbr")
}

open func state() -> String {
public func state() -> String {
return generate("address.state")
}

open func county() -> String {
public func county() -> String {
return generate("address.county")
}

open func country() -> String {
public func country() -> String {
return generate("address.country")
}

open func countryCode() -> String {
public func countryCode() -> String {
return generate("address.country_code")
}

open func latitude() -> Double {
public func latitude() -> Double {
return drand48() * 180.0 - 90.0
}

open func longitude() -> Double {
public func longitude() -> Double {
return drand48() * 360.0 - 180.0
}
}
8 changes: 4 additions & 4 deletions Source/Generators/App.swift
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
open class App: Generator {
public final class App: Generator {

open func name() -> String {
public func name() -> String {
return generate("app.name")
}

open func version() -> String {
public func version() -> String {
return numerify(generate("app.version"))
}

open func author() -> String {
public func author() -> String {
return generate("app.author")
}
}
8 changes: 4 additions & 4 deletions Source/Generators/Business.swift
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import Foundation

open class Business: Generator {
public final class Business: Generator {

open func creditCardNumber() -> String {
public func creditCardNumber() -> String {
return generate("business.credit_card_numbers")
}

open func creditCardType() -> String {
public func creditCardType() -> String {
return generate("business.credit_card_types")
}

open func creditCardExpiryDate() -> Date? {
public func creditCardExpiryDate() -> Date? {
let dateString = generate("business.credit_card_expiry_dates")
return dateFormatter.date(from: dateString)
}
Expand Down
Loading

0 comments on commit 65f8afb

Please sign in to comment.