Skip to content

Commit

Permalink
Update public APIs with new Swift 3 naming guidelines
Browse files Browse the repository at this point in the history
  • Loading branch information
joanromano committed Sep 29, 2016
1 parent a819361 commit 279e4ba
Show file tree
Hide file tree
Showing 10 changed files with 67 additions and 67 deletions.
2 changes: 1 addition & 1 deletion README.playground/Contents.swift
Expand Up @@ -30,7 +30,7 @@ struct CustomZoo: CustomSerializable {

// this is a really simple `CustomSerializable` that could be achieved with `Serializable` by just using a property "species" (dictionary).
// See JSONAPI implementation for more complex, real life, examples.
func customSerialize(_ keyTransformer: KeyTransformer?) -> Any? {
func customSerialized(transformingKeys keyTransformer: KeyTransformer?) -> Any? {
// transformer will be not nill when this object is wrapped into a `SerializationTransformer` (e.g. `SnakeCaseTransformer`)... if the object doesn't need key transformation just ignore it
let key: (String) -> (String) = { (key) in
return keyTransformer?(key) ?? key
Expand Down
2 changes: 1 addition & 1 deletion Source/JSONAPILinks.swift
Expand Up @@ -37,7 +37,7 @@ public enum JSONAPILink: CustomSerializable {
/**
The `JSONAPILink` implementation of `CustomSerializable` returns directly the link for `.simple` or returns a dictionary containing the link (href key) and the serialized meta object (meta key) for `.object`
*/
public func customSerialize(_ keyTransformer: KeyTransformer?) -> Any? {
public func customSerialized(transformingKeys keyTransformer: KeyTransformer?) -> Any? {
switch self {
case let .object(href, meta):
var serializedObject: [String: Any] = ["href" : href]
Expand Down
78 changes: 39 additions & 39 deletions Source/JSONAPISerializer.swift

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions Source/Router.swift
Expand Up @@ -36,7 +36,7 @@ public struct Request {
/**
A protocol to adopt when a `Serializable object needs to also provide response status code and/or headerFields
For example you may use `Response` to wrap your `Serializable` object to just achieve the result or directly implement the protocol.
For example `JSONAPISerializer` implement the protocol in order to be able to provide custom status code in the response.
For example `JSONAPIError` implement the protocol in order to be able to provide custom status code in the response.
*/
public protocol ResponseFieldsProvider: CustomSerializable {
/// The response status code
Expand All @@ -52,7 +52,7 @@ public protocol ResponseFieldsProvider: CustomSerializable {
extension ResponseFieldsProvider {

/// The default implementation just return the serialized body.
public func customSerialize(_ keyTransformer: KeyTransformer?) -> Any? {
public func customSerialized(transformingKeys keyTransformer: KeyTransformer?) -> Any? {
return body.serialized(transformingKeys: keyTransformer)
}
}
Expand Down
2 changes: 1 addition & 1 deletion Source/SerializationTransformer.swift
Expand Up @@ -42,7 +42,7 @@ extension SerializationTransformer {
- returns: The serialized wrapped object with transformed keys.
*/
public func customSerialize(_ keyTransformer: KeyTransformer?) -> Any? {
public func customSerialized(transformingKeys keyTransformer: KeyTransformer?) -> Any? {
return wrapped.serialized { (string) in
let transformed = self.transform(key: string)
return keyTransformer?(transformed) ?? transformed
Expand Down
12 changes: 6 additions & 6 deletions Source/Serializer.swift
Expand Up @@ -26,7 +26,7 @@ public protocol CustomSerializable: Serializable {
- returns: You should return either another `Serializable` object (also `Array` or `Dictionary`) containing other Serializable objects or property list types that can be serialized into json (primitive types).
*/
func customSerialize(_ keyTransformer: KeyTransformer?) -> Any?
func customSerialized(transformingKeys keyTransformer: KeyTransformer?) -> Any?
}

public extension Serializable {
Expand All @@ -39,7 +39,7 @@ public extension Serializable {
*/
func serialized(transformingKeys keyTransformer: KeyTransformer? = nil) -> Any? {
if let object = self as? CustomSerializable {
return object.customSerialize(keyTransformer)
return object.customSerialized(transformingKeys: keyTransformer)
}
return Kakapo.serialize(self, keyTransformer: keyTransformer)
}
Expand All @@ -61,7 +61,7 @@ public extension Serializable {

extension Array: CustomSerializable {
/// `Array` is serialized by returning an `Array` containing its serialized elements
public func customSerialize(_ keyTransformer: KeyTransformer?) -> Any? {
public func customSerialized(transformingKeys keyTransformer: KeyTransformer?) -> Any? {
return flatMap { (element) -> Any? in
return serializeObject(element, keyTransformer: keyTransformer)
}
Expand All @@ -70,7 +70,7 @@ extension Array: CustomSerializable {

extension Dictionary: CustomSerializable {
/// `Dictionary` is serialized by creating a Dictionary with the same keys and values serialized
public func customSerialize(_ keyTransformer: KeyTransformer?) -> Any? {
public func customSerialized(transformingKeys keyTransformer: KeyTransformer?) -> Any? {
var dictionary = [String: Any]()
for (key, value) in self {
assert(key is String, "key must be a String to be serialized to JSON")
Expand All @@ -85,7 +85,7 @@ extension Dictionary: CustomSerializable {

extension Optional: CustomSerializable {
/// `Optional` serializes its inner object or nil if nil
public func customSerialize(_ keyTransformer: KeyTransformer?) -> Any? {
public func customSerialized(transformingKeys keyTransformer: KeyTransformer?) -> Any? {
switch self {
case let .some(value):
return serializeObject(value, keyTransformer: keyTransformer)
Expand All @@ -97,7 +97,7 @@ extension Optional: CustomSerializable {

extension PropertyPolicy {
/// `PropertyPolicy` serializes as nil when `.none`, as `NSNull` when `.null` or serialize the object for `.some`
public func customSerialize(_ keyTransformer: KeyTransformer?) -> Any? {
public func customSerialized(transformingKeys keyTransformer: KeyTransformer?) -> Any? {
switch self {
case .none:
return nil
Expand Down
6 changes: 3 additions & 3 deletions Source/Store.swift
Expand Up @@ -195,12 +195,12 @@ public final class Store {
Filter all the objects in the store of a given Storable Type that satisfy the a given handler
- parameter (unnamed): The Storable Type to be filtered
- parameter includeElement: The predicate to satisfy the filtering
- parameter isIncluded: The predicate to satisfy the filtering
- returns: An array containing the filtered Storable objects
*/
public func filter<T: Storable>(_: T.Type, includeElement: (T) -> Bool) -> [T] {
return findAll(T.self).filter(includeElement)
public func filter<T: Storable>(_: T.Type, isIncluded: (T) -> Bool) -> [T] {
return findAll(T.self).filter(isIncluded)
}

/**
Expand Down
12 changes: 6 additions & 6 deletions Tests/JSONAPITests.swift
Expand Up @@ -58,7 +58,7 @@ class JSONAPISpec: QuickSpec {
let id: String
let title: String

func customSerialize(_ keyTransformer: KeyTransformer?) -> Any? {
func customSerialized(transformingKeys keyTransformer: KeyTransformer?) -> Any? {
return ["foo": "bar"]
}
}
Expand Down Expand Up @@ -345,7 +345,7 @@ class JSONAPISpec: QuickSpec {
let dog = Dog(id: "22", name: "Joan", cat: Cat(id: "55", name: "Max"))
let user = User(id: "11", name: "Alex", dog: dog, cats: cats)

let object = json(JSONAPISerializer(user, includeChildren: true))
let object = json(JSONAPISerializer(user, includingChildren: true))
let included = object["included"].arrayValue
expect(included.count).to(equal(4))
}
Expand Down Expand Up @@ -417,19 +417,19 @@ class JSONAPISpec: QuickSpec {
context("included PropertyPolicies") {

it("should handle PropertyPolicy.none") {
let object = json(JSONAPISerializer(Policy<User>(id: "1111", policy: .none), includeChildren: true))
let object = json(JSONAPISerializer(Policy<User>(id: "1111", policy: .none), includingChildren: true))
let included = includedRelationshipsById(object)
expect(included.count).to(equal(0))
}

it("should handle PropertyPolicy.null") {
let object = json(JSONAPISerializer(Policy<User>(id: "1111", policy: .null), includeChildren: true))
let object = json(JSONAPISerializer(Policy<User>(id: "1111", policy: .null), includingChildren: true))
let included = includedRelationshipsById(object)
expect(included.count).to(equal(0))
}

it("should handle PropertyPolicy.some(T)") {
let object = json(JSONAPISerializer(Policy<User>(id: "1111", policy: .some(user)), includeChildren: true))
let object = json(JSONAPISerializer(Policy<User>(id: "1111", policy: .some(user)), includingChildren: true))
let included = includedRelationshipsById(object)
let dog = included["22"]

Expand All @@ -438,7 +438,7 @@ class JSONAPISpec: QuickSpec {
}

it("should be empty if PropertyPolicy is not a JSONAPIEntity") {
let object = json(JSONAPISerializer(Policy<Int>(id: "1111", policy: .some(1)), includeChildren: true))
let object = json(JSONAPISerializer(Policy<Int>(id: "1111", policy: .some(1)), includingChildren: true))
let included = includedRelationshipsById(object)
expect(included.count).to(equal(0))
}
Expand Down
2 changes: 1 addition & 1 deletion Tests/SerializerTests.swift
Expand Up @@ -28,7 +28,7 @@ class SerializeSpec: QuickSpec {
struct CustomUser: CustomSerializable {
let name: String

func customSerialize(_ keyTransformer: KeyTransformer?) -> Any? {
func customSerialized(transformingKeys keyTransformer: KeyTransformer?) -> Any? {
let key = keyTransformer?("customName") ?? "customName"
return [key: name]
}
Expand Down
14 changes: 7 additions & 7 deletions Tests/StoreTests.swift
Expand Up @@ -188,7 +188,7 @@ class StoreTests: QuickSpec {
return User(firstName: "Hector", lastName: "Zarco", age:25, id: id)
}

let userArray = sut.filter(User.self, includeElement: { (item) -> Bool in
let userArray = sut.filter(User.self, isIncluded: { (item) -> Bool in
return item.lastName == "Manzella"
})

Expand Down Expand Up @@ -381,7 +381,7 @@ class StoreTests: QuickSpec {
}

it("should not deadlock when writing into the store during a reading operation") {
let result = sut.filter(User.self, includeElement: { (_) -> Bool in
let result = sut.filter(User.self, isIncluded: { (_) -> Bool in
sut.create(User.self)
return true
})
Expand All @@ -390,7 +390,7 @@ class StoreTests: QuickSpec {
}

it("should not deadlock when synchronously writing from another queue into the store during a reading operation") {
let result = sut.filter(User.self, includeElement: { (_) -> Bool in
let result = sut.filter(User.self, isIncluded: { (_) -> Bool in
let _ = queue.sync {
sut.create(User.self)
}
Expand All @@ -401,7 +401,7 @@ class StoreTests: QuickSpec {
}

it("should not deadlock when reading the store during a read operation") {
let result = sut.filter(User.self, includeElement: { (_) -> Bool in
let result = sut.filter(User.self, isIncluded: { (_) -> Bool in
let _ = sut.findAll(User.self)
return true
})
Expand All @@ -410,7 +410,7 @@ class StoreTests: QuickSpec {
}

it("should not deadlock when synchronously reading the store from another queue during a reading operation") {
let result = sut.filter(User.self, includeElement: { (_) -> Bool in
let result = sut.filter(User.self, isIncluded: { (_) -> Bool in
let _ = queue.sync {
sut.findAll(User.self)
}
Expand Down Expand Up @@ -463,7 +463,7 @@ class StoreTests: QuickSpec {
}

it("should not deadlock when deleting into store during a reading operation") {
let result = sut.filter(User.self, includeElement: { (_) -> Bool in
let result = sut.filter(User.self, isIncluded: { (_) -> Bool in
try! sut.delete(sut.find(User.self, id: "0")!)
return true
})
Expand All @@ -475,7 +475,7 @@ class StoreTests: QuickSpec {
}

it("should not deadlock when updating into store during a reading operation") {
let result = sut.filter(User.self, includeElement: { (_) -> Bool in
let result = sut.filter(User.self, isIncluded: { (_) -> Bool in
try! sut.update(User(firstName: "Alex", lastName: "Manzella", age: 30, id: "0"))
return true
})
Expand Down

0 comments on commit 279e4ba

Please sign in to comment.