|
| 1 | +/* |
| 2 | + * Copyright 2020 Google LLC |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +#import "FIREmulatorSettings.h" |
| 18 | + |
| 19 | +/** :nodoc: */ |
| 20 | +NSString *const FIREmulatorServiceDatabase = @"FIREmulatorServiceDatabase"; |
| 21 | + |
| 22 | +/** :nodoc: */ |
| 23 | +NSString *const FIREmulatorServiceFirestore = @"FIREmulatorServiceFirestore"; |
| 24 | + |
| 25 | +/** :nodoc: */ |
| 26 | +NSString *const FIREmulatorServiceAuth = @"FIREmulatorServiceAuth"; |
| 27 | + |
| 28 | +/** :nodoc: */ |
| 29 | +NSString *const FIREmulatorServiceFunctions = @"FIREmulatorServiceFunctions"; |
| 30 | + |
| 31 | +@implementation FIREmulatorServiceSettings |
| 32 | + |
| 33 | +- (instancetype)init { |
| 34 | + NSAssert(NO, @"The default initializer is unavailable. Call the designated initializer instead."); |
| 35 | +} |
| 36 | + |
| 37 | +- (instancetype)initWithHost:(NSString *)host port:(NSInteger)port { |
| 38 | + NSAssert(host != nil, @"A nonnull host is required"); |
| 39 | + self = [super init]; |
| 40 | + if (self != nil) { |
| 41 | + _host = [host copy]; |
| 42 | + _port = port; |
| 43 | + } |
| 44 | + return self; |
| 45 | +} |
| 46 | + |
| 47 | +- (instancetype)copyWithZone:(NSZone *)zone { |
| 48 | + return self; // instances are immutable, so return self |
| 49 | +} |
| 50 | + |
| 51 | +@end |
| 52 | + |
| 53 | +@interface FIREmulatorSettings () |
| 54 | + |
| 55 | +@property(nonatomic, copy, nonnull) |
| 56 | + NSDictionary<FIREmulatorService *, FIREmulatorServiceSettings *> *settings; |
| 57 | + |
| 58 | +@end |
| 59 | + |
| 60 | +@implementation FIREmulatorSettings |
| 61 | + |
| 62 | +- (instancetype)init { |
| 63 | + NSAssert(NO, @"The default initializer is unavailable. Call the designated initializer instead."); |
| 64 | +} |
| 65 | + |
| 66 | +- (instancetype)initWithSettings: |
| 67 | + (NSDictionary<FIREmulatorService *, FIREmulatorServiceSettings *> *)settings { |
| 68 | + NSAssert(settings.count > 0, |
| 69 | + @"Creating emulator settings requires non-empty service settings list."); |
| 70 | + self = [super init]; |
| 71 | + if (self != nil) { |
| 72 | + _settings = [settings copy]; |
| 73 | + } |
| 74 | + return self; |
| 75 | +} |
| 76 | + |
| 77 | +- (instancetype)initWithServiceSettings:(FIREmulatorServiceSettings *)settings |
| 78 | + forService:(FIREmulatorService *)service { |
| 79 | + NSAssert(settings != nil); |
| 80 | + NSAssert(service != nil); |
| 81 | + NSDictionary *settings = @{service : settings}; |
| 82 | + return [self initWithSettings:settings]; |
| 83 | +} |
| 84 | + |
| 85 | +- (instancetype)copyWithZone:(NSZone *)zone { |
| 86 | + return self; // immutable, so return self |
| 87 | +} |
| 88 | + |
| 89 | +- (FIREmulatorSettings *)settingsForService:(FIREmulatorService *)service { |
| 90 | + return self.settings[service]; |
| 91 | +} |
| 92 | + |
| 93 | +@end |
0 commit comments