Skip to content

Commit

Permalink
Merge pull request #179 from scribd/stephane/projects_param
Browse files Browse the repository at this point in the history
Add projects attribute to Weaver to filter out dependencies by project names
  • Loading branch information
Stephane Magne authored Jan 30, 2023
2 parents f0e40df + a35cbbd commit 69f50d6
Show file tree
Hide file tree
Showing 15 changed files with 295 additions and 96 deletions.
2 changes: 1 addition & 1 deletion Sample/API/Generated/Weaver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Foundation
import UIKit

// swiftlint:disable all
/// This file is generated by Weaver 1.1.4
/// This file is generated by Weaver 1.1.5
/// DO NOT EDIT!

final class MainDependencyContainer {
Expand Down
2 changes: 1 addition & 1 deletion Sample/Sample/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

private let dependencies = MainDependencyContainer.appDelegateDependencyResolver()

@Weaver(.registration)
@Weaver(.registration, projects: ["Sample"])
private var logger: Logger

@Weaver(.registration, builder: AppDelegate.makeURLSession)
Expand Down
26 changes: 13 additions & 13 deletions Sample/Sample/Generated/Weaver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Foundation
import UIKit

// swiftlint:disable all
/// This file is generated by Weaver 1.1.4
/// This file is generated by Weaver 1.1.5
/// DO NOT EDIT!

@objc(SampleIOSMainDependencyContainer)
Expand Down Expand Up @@ -213,10 +213,9 @@ final class MainDependencyContainer: NSObject {
private func personManagerDependencyResolver() -> PersonManagerDependencyResolver {
let _self = MainDependencyContainer()
var _builders = Dictionary<String, Any>()
_builders["logger"] = Provider.lazyBuilder( { (_: Optional<Provider.ParametersCopier>) -> Logger in return Logger() })
_builders["logger"] = _self.loggerBuilder
_builders["movieAPI"] = _self.movieAPIBuilder
_self.provider.addBuilders(_builders)
_ = _self.logger
MainDependencyContainer._pushDynamicResolver({ _self.logger })
MainDependencyContainer._pushDynamicResolver({ _self.movieAPI })
return _self
Expand All @@ -225,10 +224,9 @@ final class MainDependencyContainer: NSObject {
private func reviewManagerDependencyResolver() -> ReviewManagerDependencyResolver {
let _self = MainDependencyContainer()
var _builders = Dictionary<String, Any>()
_builders["logger"] = Provider.lazyBuilder( { (_: Optional<Provider.ParametersCopier>) -> Logger in return Logger() })
_builders["logger"] = loggerBuilder
_builders["movieAPI"] = movieAPIBuilder
_self.provider.addBuilders(_builders)
_ = _self.logger
MainDependencyContainer._pushDynamicResolver({ _self.logger })
MainDependencyContainer._pushDynamicResolver({ _self.movieAPI })
return _self
Expand All @@ -238,7 +236,6 @@ final class MainDependencyContainer: NSObject {
let _self = MainDependencyContainer(provider: provider.copy())
let _inputProvider = _self.provider.copy()
var _builders = Dictionary<String, Any>()
_builders["logger"] = Provider.lazyBuilder( { (_: Optional<Provider.ParametersCopier>) -> Logger in return Logger() })
_builders["movieController"] = Provider.weakLazyBuilder(
{ (copyParameters: Optional<Provider.ParametersCopier>) -> UIViewController in
defer { MainDependencyContainer._dynamicResolversLock.unlock() }
Expand All @@ -250,11 +247,11 @@ final class MainDependencyContainer: NSObject {
}
)
_builders["imageManager"] = imageManagerBuilder
_builders["logger"] = loggerBuilder
_builders["movieManager"] = movieManagerBuilder
_builders["reviewManager"] = reviewManagerBuilder
_self.provider.addBuilders(_builders)
_inputProvider.addBuilders(_builders)
_ = _self.logger
MainDependencyContainer._pushDynamicResolver({ _self.logger })
MainDependencyContainer._pushDynamicResolver({ _self.movieManager })
MainDependencyContainer._pushDynamicResolver(_self.movieController)
Expand All @@ -265,18 +262,17 @@ final class MainDependencyContainer: NSObject {
let _self = MainDependencyContainer(provider: provider.copy())
let _inputProvider = _self.provider
var _builders = Dictionary<String, Any>()
_builders["logger"] = Provider.lazyBuilder( { (_: Optional<Provider.ParametersCopier>) -> Logger in return Logger() })
_builders["reviewController"] = Provider.weakLazyBuilder(
{ (_: Optional<Provider.ParametersCopier>) -> WSReviewViewController in
let _inputContainer = MainDependencyContainer(provider: _inputProvider.copy())
return WSReviewViewController.make(_inputContainer as WSReviewViewControllerInputDependencyResolver)
}
)
_builders["imageManager"] = imageManagerBuilder
_builders["logger"] = loggerBuilder
_builders["movieManager"] = movieManagerBuilder
_builders["reviewManager"] = reviewManagerBuilder
_self.provider.addBuilders(_builders)
_ = _self.logger
MainDependencyContainer._pushDynamicResolver({ _self.logger })
MainDependencyContainer._pushDynamicResolver({ _self.movieID })
MainDependencyContainer._pushDynamicResolver({ _self.movieTitle })
Expand Down Expand Up @@ -369,7 +365,8 @@ struct Weaver<ConcreteType, AbstractType> {
escaping: Bool = false,
builder: Optional<Any> = nil,
objc: Bool = false,
platforms: Array<MainDependencyContainer.Platform> = []) {
platforms: Array<MainDependencyContainer.Platform> = [],
projects: Array<String> = []) {
// no-op
}

Expand All @@ -385,7 +382,8 @@ extension Weaver where ConcreteType == Void {
escaping: Bool = false,
builder: Optional<Any> = nil,
objc: Bool = false,
platforms: Array<MainDependencyContainer.Platform> = []) {
platforms: Array<MainDependencyContainer.Platform> = [],
projects: Array<String> = []) {
// no-op
}
}
Expand All @@ -403,7 +401,8 @@ struct WeaverP2<ConcreteType, AbstractType, P1, P2> {
escaping: Bool = false,
builder: Optional<Any> = nil,
objc: Bool = false,
platforms: Array<MainDependencyContainer.Platform> = []) {
platforms: Array<MainDependencyContainer.Platform> = [],
projects: Array<String> = []) {
// no-op
}

Expand All @@ -419,7 +418,8 @@ extension WeaverP2 where ConcreteType == Void {
escaping: Bool = false,
builder: Optional<Any> = nil,
objc: Bool = false,
platforms: Array<MainDependencyContainer.Platform> = []) {
platforms: Array<MainDependencyContainer.Platform> = [],
projects: Array<String> = []) {
// no-op
}
}
Expand Down
2 changes: 1 addition & 1 deletion Sample/Sample/Manager/PersonManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ final class PersonManager: PersonManaging {

// weaver: self.isIsolated = true

@Weaver(.registration)
@Weaver(.reference)
private var logger: Logger

@Weaver(.reference)
Expand Down
2 changes: 1 addition & 1 deletion Sample/Sample/Manager/ReviewManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import API

final class ReviewManager: ReviewManaging {

@Weaver(.registration)
@Weaver(.reference)
private var logger: Logger

@Weaver(.reference)
Expand Down
2 changes: 1 addition & 1 deletion Sample/Sample/View/HomeViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ final class HomeViewController: UIViewController {

private var movies = [Movie]()

@Weaver(.registration)
@Weaver(.reference, platforms: [.iOS])
private var logger: Logger

@Weaver(.reference)
Expand Down
2 changes: 1 addition & 1 deletion Sample/Sample/View/MovieViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ final class MovieViewController: UIViewController {
let overview: String?
}

@Weaver(.registration)
@Weaver(.reference)
private var logger: Logger

@Weaver(.parameter)
Expand Down
10 changes: 10 additions & 0 deletions Sources/WeaverCodeGen/Codable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ extension ConfigurationAttribute: Codable {
self = .escaping(value: try container.decode(Bool.self, forKey: .value))
case .platforms:
self = .platforms(values: try container.decode([Platform].self, forKey: .value))
case .projects:
self = .projects(values: try container.decode([String].self, forKey: .value))
}
}

Expand Down Expand Up @@ -58,6 +60,9 @@ extension ConfigurationAttribute: Codable {
case .platforms(let value):
try container.encode(ConfigurationAttributeName.platforms, forKey: .name)
try container.encode(value, forKey: .value)
case .projects(let value):
try container.encode(ConfigurationAttributeName.projects, forKey: .name)
try container.encode(value, forKey: .value)
}
}
}
Expand Down Expand Up @@ -95,6 +100,7 @@ extension ConfigurationAttributeName: Codable {
case setter = "set"
case escaping = "e"
case platforms = "p"
case projects = "j"

init(_ value: ConfigurationAttributeName) {
switch value {
Expand All @@ -112,6 +118,8 @@ extension ConfigurationAttributeName: Codable {
self = .escaping
case .platforms:
self = .platforms
case .projects:
self = .projects
}
}

Expand All @@ -131,6 +139,8 @@ extension ConfigurationAttributeName: Codable {
return .escaping
case .platforms:
return .platforms
case .projects:
return .projects
}
}
}
Expand Down
5 changes: 4 additions & 1 deletion Sources/WeaverCodeGen/Configuration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,17 @@ struct DependencyConfiguration: Configuration {
let escaping: Bool

let platforms: Set<Platform>


let projects: Set<String>

init(with attributes: [ConfigurationAttributeName: ConfigurationAttribute]?) {
customBuilder = attributes?[.customBuilder]?.stringValue
scope = attributes?[.scope]?.scopeValue ?? .default
doesSupportObjc = attributes?[.doesSupportObjc]?.boolValue ?? false
setter = attributes?[.setter]?.boolValue ?? false
escaping = attributes?[.escaping]?.boolValue ?? false
platforms = Set(attributes?[.platforms]?.platformValues ?? [])
projects = Set(attributes?[.projects]?.projectValues ?? [])
}
}

Expand Down
Loading

0 comments on commit 69f50d6

Please sign in to comment.