Home

Awesome

:factory: FactoryProvider :factory:

Build Status Version Platform GitHub license GitHub release Xcode Swift Swift Package Manager

Generate boilerplate of factory Swift framework.

Requirements

Platforms

FactoryProvider works on the following platforms:

Supports

FactoryProvider

1. Installation

CocoaPods

FactoryProvider runtime is available through CocoaPods. To install it, simply add the following line to your test target in your Podfile:

pod "FactoryProvider"

And add the following Run script build phase to your test target's Build Phases:

"${PODS_ROOT}/FactoryProvider/generate" --config .factory.yml

After running once, locate Factories.generated.swift and drag it into your Xcode test target group.

.factory.yml

includes: # paths of file or directory to generate
  - Input/SubInput1
  - Input/SubInput2/Source.swift
excludes: # paths of file or directory not to generate
  - Input/SubInput1/SubSubInput
  - Input/SubInput2/Source.swift
testables: # testable targets
  - target1
  - target2
output: output/Factories.generated.swift # path of generated file

2. Usage

You can get a instance to call Factory<TypeName>.provide(). Each properties are set to default value.

struct Climber {
    let name: String
    let age: Int
}

let climber = Factory<Climber>.provide()
// Climber(name: "", age: 0)

 let optClimber = Factory<Climber?>.provide()
// Optional(Climber(name: "", age: 0))

 let arrayClimber = Factory<[Climber]>.provide()
// [Climber(name: "", age: 0)]

3. Lens

Factory<TypeName>.provide() provides fixed instance. You can modify each property by Lens.

Get

let name = Factory<Climber>.provide().name or Lens<Climber>.name().get(Factory<Climber>.provide())
// ""

Set

import FactoryProvider

let climber = Factory<Climber>.provide() |> Lens<Climber>.name() *~ "Climber"
// Climber(name: "Climber", age: 0)

Modify

import FactoryProvider

let name = Factory<Climber>.provide() |> Lens<Climber>.name() *~ { "Climber" |> { $0 + $0 } }()
// Climber(name: "ClimberClimber", age: 0)

Compose

import FactoryProvider

struct Climber {
    let id: Id
    let name: String
    
    struct Id {
        let value: String
    }
}

let climber1 = Factory<Climber>.provide()
// Climber(id: Id(value: ""), name: "")

let climber2 = climber1 |> Lens<Climber>.id() * Lens<Climber.Id>.value() *~ "id"
// Climber(id: Id(value: "id"), name: "")

Notice

Generics

If you want to contains type using generics, you should use 0.4.1.

pod "FactoryProvider", '~> 0.4.1'

Libraries

License

FactoryProvider is available under the MIT License.