Skip to content
This repository was archived by the owner on Nov 24, 2020. It is now read-only.

Commit 89e9975

Browse files
authored
Merge pull request #59 from fabcarvalhal/master
Public modifiers and MoneyPrimitiveType
2 parents c76d500 + ee97aa1 commit 89e9975

File tree

2 files changed

+30
-28
lines changed

2 files changed

+30
-28
lines changed

src/target/swift.cr

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ abstract class SwiftTarget < Target
1212
when AST::BoolPrimitiveType ; "Bool"
1313
when AST::BytesPrimitiveType ; "Data"
1414
when AST::VoidPrimitiveType ; "NoReply"
15+
when AST::MoneyPrimitiveType ; "Int64"
1516
else
1617
raise "BUG! Should handle primitive #{t.class}"
1718
end
@@ -38,6 +39,7 @@ abstract class SwiftTarget < Target
3839
when AST::StringPrimitiveType ; path
3940
when AST::IntPrimitiveType ; path
4041
when AST::UIntPrimitiveType ; path
42+
when AST::MoneyPrimitiveType ; path
4143
when AST::FloatPrimitiveType ; path
4244
when AST::DatePrimitiveType ; path
4345
when AST::DateTimePrimitiveType; path
@@ -55,11 +57,11 @@ abstract class SwiftTarget < Target
5557

5658
def generate_struct_type(t)
5759
String.build do |io|
58-
io << "class #{t.name}: Codable {\n"
60+
io << "public class #{t.name}: Codable {\n"
5961
t.fields.each do |field|
60-
io << ident "var #{field.name}: #{native_type field.type}\n"
62+
io << ident "public var #{field.name}: #{native_type field.type}\n"
6163
end
62-
io << ident "\nvar copy: #{t.name} {\n"
64+
io << ident "\npublic var copy: #{t.name} {\n"
6365
io << ident ident "return #{t.name}(\n"
6466
io << ident ident ident t.fields.map { |field| "#{field.name}: #{generate_property_copy(field.type, field.name)}" }.join(",\n")
6567
io << ident ident "\n)\n"
@@ -74,7 +76,7 @@ abstract class SwiftTarget < Target
7476
io << ident <<-END
7577
7678
77-
init() {
79+
public init() {
7880
7981
END
8082
t.fields.each do |field|
@@ -83,7 +85,7 @@ END
8385
io << ident <<-END
8486
}
8587
86-
init(#{t.fields.map { |f| "#{f.name}: #{native_type f.type}" }.join(", ")}) {
88+
public init(#{t.fields.map { |f| "#{f.name}: #{native_type f.type}" }.join(", ")}) {
8789
8890
END
8991
t.fields.each do |field|
@@ -92,7 +94,7 @@ END
9294
io << ident <<-END
9395
}
9496
95-
init(json: [String: Any]) throws {
97+
public init(json: [String: Any]) throws {
9698
let jsonData = try JSONSerialization.data(withJSONObject: json, options: .prettyPrinted)
9799
let decodedSelf = try decoder.decode(#{t.name}.self, from: jsonData)\n
98100
@@ -103,7 +105,7 @@ END
103105
io << ident <<-END
104106
}
105107
106-
func toJSON() -> [String: Any] {
108+
public func toJSON() -> [String: Any] {
107109
var json = [String: Any]()
108110
109111
END
@@ -122,9 +124,9 @@ END
122124
def generate_enum_type(t)
123125
String.build do |io|
124126
if t.name == "ErrorType"
125-
io << "enum #{t.name}: String, Error, Codable {\n"
127+
io << "public enum #{t.name}: String, Error, Codable {\n"
126128
else
127-
io << "enum #{t.name}: String, CaseIterable, DisplayableValue, Codable {\n"
129+
io << "public enum #{t.name}: String, CaseIterable, DisplayableValue, Codable {\n"
128130
end
129131

130132
t.values.each do |value|
@@ -142,7 +144,7 @@ END
142144
io << ident ident "return dictionary\n"
143145
io << ident "}\n"
144146

145-
io << ident "\nstatic func allDisplayableValues() -> [String] {\n"
147+
io << ident "\npublic static func allDisplayableValues() -> [String] {\n"
146148
io << ident ident "var displayableValues: [String] = []\n"
147149
io << ident ident "for enumCase in self.allCases {\n"
148150
io << ident ident ident "displayableValues.append(enumCase.displayableValue)\n"
@@ -158,7 +160,7 @@ END
158160
case t
159161
when AST::StringPrimitiveType
160162
"\"\""
161-
when AST::IntPrimitiveType, AST::UIntPrimitiveType, AST::FloatPrimitiveType
163+
when AST::IntPrimitiveType, AST::UIntPrimitiveType, AST::FloatPrimitiveType, AST::MoneyPrimitiveType
162164
"0"
163165
when AST::BoolPrimitiveType
164166
"false"
@@ -185,7 +187,7 @@ END
185187

186188
def type_to_json(t : AST::Type, src : String)
187189
case t
188-
when AST::StringPrimitiveType, AST::IntPrimitiveType, AST::UIntPrimitiveType, AST::FloatPrimitiveType, AST::BoolPrimitiveType
190+
when AST::StringPrimitiveType, AST::IntPrimitiveType, AST::UIntPrimitiveType, AST::FloatPrimitiveType, AST::BoolPrimitiveType, AST::MoneyPrimitiveType
189191
"#{src}"
190192
when AST::DatePrimitiveType
191193
"apiInternal.encodeDate(date: #{src})"

src/target/swift_ios.cr

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class SwiftIosTarget < SwiftTarget
66
import Alamofire
77
import KeychainSwift
88
9-
protocol ApiCallsLogic: class {\n
9+
public protocol ApiCallsLogic: class {\n
1010
END
1111

1212
@ast.operations.each do |op|
@@ -24,18 +24,18 @@ END
2424
@io << "}\n\n" # CloseAPICallsProtocol
2525
@io << <<-END
2626
27-
class API {
28-
static var customUrl: String?
29-
static var useStaging = false
30-
static var globalCallback: (_ method: String, _ result: ApiInternal.Result<Any?>, _ callback: ((ApiInternal.Result<Any?>) -> Void)?) -> Void = { _, result, callback in
27+
public class API {
28+
public static var customUrl: String?
29+
public static var useStaging = false
30+
public static var globalCallback: (_ method: String, _ result: ApiInternal.Result<Any?>, _ callback: ((ApiInternal.Result<Any?>) -> Void)?) -> Void = { _, result, callback in
3131
callback?(result)
3232
}
3333
34-
static var isEnabledAssertion = true
35-
static var calls: ApiCallsLogic = Calls()
36-
static var apiInternal = ApiInternal()
34+
public static var isEnabledAssertion = true
35+
public static var calls: ApiCallsLogic = Calls()
36+
public static var apiInternal = ApiInternal()
3737
38-
static var decoder: JSONDecoder = {
38+
public static var decoder: JSONDecoder = {
3939
let currentDecoder = JSONDecoder()
4040
currentDecoder.dateDecodingStrategy = .custom({ (decoder) -> Date in
4141
let container = try decoder.singleValueContainer()
@@ -54,7 +54,7 @@ class API {
5454
}()
5555
5656
// MARK: Struct and Enums
57-
struct NoReply: Codable {}\n\n
57+
public struct NoReply: Codable {}\n\n
5858
END
5959
# ApiCalls
6060
@io << ident(String.build do |io|
@@ -102,20 +102,20 @@ END
102102

103103
@io << <<-END
104104
105-
class ApiInternal {
105+
public class ApiInternal {
106106
var baseUrl = #{@ast.options.url.inspect}
107107
108108
// MARK: ApiInternal Inner classes
109-
enum Result<T> {
109+
public enum Result<T> {
110110
case success(T)
111111
case failure(Error)
112112
}
113113
114-
class Error: Codable {
114+
public class Error: Codable {
115115
var type: API.ErrorType
116116
var message: String
117117
118-
init(type: API.ErrorType, message: String) {
118+
public init(type: API.ErrorType, message: String) {
119119
self.type = type
120120
self.message = message
121121
}
@@ -299,11 +299,11 @@ END
299299
}
300300
}
301301
}
302-
protocol DisplayableValue: RawRepresentable {
302+
public protocol DisplayableValue: RawRepresentable {
303303
var displayableValue: String { get }
304304
}
305305
306-
extension DisplayableValue where RawValue == String {
306+
public extension DisplayableValue where RawValue == String {
307307
var displayableValue: String {
308308
return self.rawValue
309309
}

0 commit comments

Comments
 (0)