Skip to content

Commit

Permalink
Merge pull request #78 from LoganWright/rm-sub
Browse files Browse the repository at this point in the history
Rm sub
  • Loading branch information
loganwright authored Nov 8, 2016
2 parents 36de488 + 2138ccb commit a49bfdf
Show file tree
Hide file tree
Showing 65 changed files with 3,654 additions and 3 deletions.
1 change: 0 additions & 1 deletion Packages/Node-1.0.1
Submodule Node-1.0.1 deleted from 4cf8c7
39 changes: 39 additions & 0 deletions Packages/Node-1.0.1/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Xcode
#
build/
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata
*.xccheckout
*.moved-aside
DerivedData
*.hmap
*.ipa
*.xcuserstate
*.xcsmblueprint

# CocoaPods
#
# We recommend against adding the Pods directory to your .gitignore. However
# you should judge for yourself, the pros and cons are mentioned at:
# http://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control
#
Pods/

# Carthage
#
# Add this line if you want to avoid checking in source code from Carthage dependencies.
Carthage/Checkouts

Carthage/Build

# Swift Package Manager
.build/
Packages/
*.xcodeproj
10 changes: 10 additions & 0 deletions Packages/Node-1.0.1/.travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
os:
- linux
- osx
language: generic
sudo: required
dist: trusty
osx_image: xcode8
script:
- eval "$(curl -sL swift.vapor.sh/ci)"
- eval "$(curl -sL swift.vapor.sh/codecov)"
21 changes: 21 additions & 0 deletions Packages/Node-1.0.1/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) <year> <copyright holders>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
14 changes: 14 additions & 0 deletions Packages/Node-1.0.1/Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import PackageDescription

let package = Package(
name: "Node",
targets: [
Target(
name: "Node"
),
],
dependencies: [
.Package(url: "https://github.com/vapor/path-indexable.git", majorVersion: 1),
.Package(url: "https://github.com/vapor/polymorphic.git", majorVersion: 1)
]
)
24 changes: 24 additions & 0 deletions Packages/Node-1.0.1/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Node

![Swift](http://img.shields.io/badge/swift-3.0-brightgreen.svg)
[![Build Status](https://travis-ci.org/vapor/node.svg?branch=master)](https://travis-ci.org/vapor/node)
[![CircleCI](https://circleci.com/gh/vapor/node.svg?style=shield)](https://circleci.com/gh/vapor/node)
[![Code Coverage](https://codecov.io/gh/vapor/node/branch/master/graph/badge.svg)](https://codecov.io/gh/vapor/node)
[![Codebeat](https://codebeat.co/badges/a793ad97-47e3-40d9-82cf-2aafc516ef4e)](https://codebeat.co/projects/github-com-vapor-node)
[![Slack Status](http://vapor.team/badge.svg)](http://vapor.team)

The purpose of this package is to be an intermediary data layer that can allow transformation between unrelated formats. In this way any node convertible object can be converted to any other node convertible object and vice versa.

> a point at which lines or pathways intersect or branch; a central or connecting point.
## 📖 Documentation

Visit the Vapor web framework's [documentation](http://docs.vapor.codes) for instructions on how to use this package.

## 💧 Community

Join the welcoming community of fellow Vapor developers in [slack](http://vapor.team).

## 🔧 Compatibility

This library has been tested on macOS and Ubuntu.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
extension Bool: NodeConvertible {
public func makeNode(context: Context = EmptyNode) -> Node {
return .bool(self)
}

public init(node: Node, in context: Context) throws {
guard let bool = node.bool else {
throw NodeError.unableToConvert(node: node, expected: "\(Bool.self)")
}
self = bool
}
}
13 changes: 13 additions & 0 deletions Packages/Node-1.0.1/Sources/Node/Convertible/Context.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
Sometimes convertible operations require a greater context beyond
just a Node.
Any object can conform to Context and be included in initialization
*/
public protocol Context {}

extension Node : Context {}
extension Array : Context {}
extension Dictionary : Context {}

public let EmptyNode = Node.object([:])
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
extension NodeRepresentable {
/**
Map the node back to a convertible type
- parameter type: the type to map to -- can be inferred
- throws: if mapping fails
- returns: convertible representation of object
*/
public func converted<T: NodeInitializable>(
to type: T.Type = T.self,
in context: Context = EmptyNode) throws -> T {
let node = try makeNode()
return try type.init(node: node, in: context)
}
}

extension NodeInitializable {
public init(node representable: NodeRepresentable, in context: Context = EmptyNode) throws {
let node = try representable.makeNode()
try self.init(node: node, in: context)
}

public init(node representable: NodeRepresentable?, in context: Context = EmptyNode) throws {
let node = try representable?.makeNode() ?? .null
try self.init(node: node, in: context)
}
}

// MARK: Non-Homogenous

extension NodeInitializable {
public init(node representable: [String: NodeRepresentable], in context: Context = EmptyNode) throws {
var converted: [String: Node] = [:]

for (key, val) in representable {
converted[key] = try Node(node: val)
}

let node = Node.object(converted)
try self.init(node: node, in: context)
}

public init(node representable: [String: NodeRepresentable?], in context: Context = EmptyNode) throws {
var converted: [String: Node] = [:]

for (key, val) in representable {
converted[key] = try Node(node: val)
}

let node = Node.object(converted)
try self.init(node: node, in: context)
}

public init(node representable: [NodeRepresentable], in context: Context = EmptyNode) throws {
var converted: [Node] = []

for val in representable {
converted.append(try Node(node: val))
}

let node = Node.array(converted)
try self.init(node: node, in: context)
}

public init(node representable: [NodeRepresentable?], in context: Context = EmptyNode) throws {
var converted: [Node] = []

for val in representable {
converted.append(try Node(node: val))
}

let node = Node.array(converted)
try self.init(node: node, in: context)
}
}
44 changes: 44 additions & 0 deletions Packages/Node-1.0.1/Sources/Node/Convertible/Convertible.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
public protocol NodeRepresentable {
/**
Turn the convertible into a node
- throws: if convertible can not create a Node
- returns: a node if possible
*/
func makeNode(context: Context) throws -> Node
}

extension NodeRepresentable {
public func makeNode() throws -> Node {
return try makeNode(context: EmptyNode)
}
}

public protocol NodeInitializable {
/**
Initialize the convertible with a node within a context.
Context is an empty protocol to which any type can conform.
This allows flexibility. for objects that might require access
to a context outside of the node ecosystem
*/
init(node: Node, in context: Context) throws
}

extension NodeInitializable {
/**
Default initializer for cases where a custom Context is not required
*/
public init(node: Node) throws {
try self.init(node: node, in: EmptyNode)
}
}

/**
The underlying protocol used for all conversions.
This is the base of all conversions, where both sides of data are NodeConvertible.
Any NodeConvertible can be turned into any other NodeConvertible type
Json => Node => Object => Node => XML => ...
*/
public protocol NodeConvertible: NodeInitializable, NodeRepresentable {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
public protocol NodeConvertibleFloatingPointType: NodeConvertible {
var doubleValue: Double { get }
init(_ other: Double)
}

extension Float: NodeConvertibleFloatingPointType {
public var doubleValue: Double {
return Double(self)
}
}

extension Double: NodeConvertibleFloatingPointType {
public var doubleValue: Double {
return Double(self)
}
}

extension NodeConvertibleFloatingPointType {
public func makeNode(context: Context = EmptyNode) -> Node {
return .number(Node.Number(doubleValue))
}

public init(node: Node, in context: Context) throws {
guard let double = node.double else {
throw NodeError.unableToConvert(node: node, expected: "\(Self.self)")
}
self.init(double)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
extension Int: NodeConvertible {}
extension Int8: NodeConvertible {}
extension Int16: NodeConvertible {}
extension Int32: NodeConvertible {}
extension Int64: NodeConvertible {}

extension SignedInteger {
public func makeNode(context: Context = EmptyNode) -> Node {
let number = Node.Number(self.toIntMax())
return .number(number)
}

public init(node: Node, in context: Context) throws {
guard let int = node.int else {
throw NodeError.unableToConvert(node: node, expected: "\(Self.self)")
}

self.init(int.toIntMax())
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
extension Node: NodeConvertible { // Can conform to both if non-throwing implementations
public init(node: Node, in context: Context) {
self = node
}

public func makeNode(context: Context = EmptyNode) -> Node {
return self
}
}
Loading

0 comments on commit a49bfdf

Please sign in to comment.