rails_to_swift 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/rails_to_swift +1 -1
- data/lib/rails_to_swift/swift_models.rb +6 -6
- data/lib/rails_to_swift/templates/model.swift +19 -21
- data/lib/rails_to_swift/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1b0328f5b75a2159b36a2496d6ad8da3b377e76e
|
4
|
+
data.tar.gz: 1a2720d759048ecd1f54f6289f7bd98a340891cf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d54ca4fb299280000571575fe970bcba2f0354656bd7a83fde5c22199cfc4e7f382a8e3398101d5e87673b5a80912d4a760fdd6ce82e149c51cd93e95a0c35b0
|
7
|
+
data.tar.gz: 4c236a8870a3480ae941b8b21fe010c622979609d30a9de0a36b1c5c612bf3ff463628d7c28bb3a2d7fbb2013e9f32a7a9cf714f15d8d52435b93ca50e154f3c
|
data/bin/rails_to_swift
CHANGED
@@ -143,17 +143,17 @@ module SwiftModels
|
|
143
143
|
cols = cols.each do |c|
|
144
144
|
if c.name.eql?("id")
|
145
145
|
id = c
|
146
|
-
elsif (c.name.eql?("created_at") || c.name.eql?("updated_at"))
|
147
|
-
|
148
|
-
elsif c.name[-3,3].eql?("_id")
|
149
|
-
|
146
|
+
# elsif (c.name.eql?("created_at") || c.name.eql?("updated_at"))
|
147
|
+
# timestamps << c
|
148
|
+
# elsif c.name[-3,3].eql?("_id")
|
149
|
+
# associations << c
|
150
150
|
else
|
151
151
|
rest_cols << c
|
152
152
|
end
|
153
153
|
end
|
154
|
-
[rest_cols
|
154
|
+
[rest_cols].each {|a| a.sort_by!(&:name) }
|
155
155
|
|
156
|
-
return ([id] << rest_cols << timestamps
|
156
|
+
return ([id] << rest_cols << timestamps).flatten
|
157
157
|
end
|
158
158
|
|
159
159
|
end
|
@@ -1,10 +1,13 @@
|
|
1
1
|
//
|
2
2
|
// <%= @class_name %>.swift
|
3
|
+
// Generated by RailsToSwift
|
4
|
+
// https://github.com/JoshJuncker/RailsToSwift
|
3
5
|
//
|
4
6
|
|
5
7
|
import Foundation
|
6
8
|
|
7
9
|
final class <%= @class_name %>: ResponseObjectSerializable, ResponseCollectionSerializable {
|
10
|
+
|
8
11
|
<% @columns.each do |col| %>
|
9
12
|
<% if col.not_null %>
|
10
13
|
<%= "var #{col.formatted_name}:#{col.formatted_type}?" %>
|
@@ -15,47 +18,42 @@ final class <%= @class_name %>: ResponseObjectSerializable, ResponseCollectionSe
|
|
15
18
|
<% end %>
|
16
19
|
|
17
20
|
init?(response: NSHTTPURLResponse, representation: AnyObject) {
|
21
|
+
|
22
|
+
<% @columns.each do |col| %>
|
23
|
+
<% if col.not_null %>
|
24
|
+
<%= "assert(representation.valueForKey(\"#{col.name}\") != nil, \"Expected #{col.name} to not be nil.\")" %>
|
25
|
+
|
26
|
+
<% end %>
|
27
|
+
<% end %>
|
28
|
+
|
18
29
|
<% @columns.each do |col| %>
|
19
30
|
<% if col.type == "string" %>
|
20
|
-
<%= "
|
31
|
+
<%= "#{col.formatted_name} = (representation.valueForKey(\"#{col.name}\") as? String) ?? \"\"" %>
|
21
32
|
<% elsif col.type == "integer" %>
|
22
|
-
<%= "
|
33
|
+
<%= "#{col.formatted_name} = (representation.valueForKey(\"#{col.name}\") as? Int) ?? -1" %>
|
23
34
|
<% elsif col.type == "float" %>
|
24
|
-
<%= "
|
35
|
+
<%= "#{col.formatted_name} = (representation.valueForKey(\"#{col.name}\") as? Float) ?? -1.0" %>
|
25
36
|
<% elsif col.type == "datetime" %>
|
26
|
-
<%= "
|
37
|
+
<%= "#{col.formatted_name} = NSDate.fromRails(representation.valueForKey(\"#{col.name}\") as? String ?? \"\")" %>
|
27
38
|
<% elsif col.type == "text" %>
|
28
|
-
<%= "
|
39
|
+
<%= "#{col.formatted_name} = (representation.valueForKey(\"#{col.name}\") as? String) ?? \"\"" %>
|
29
40
|
<% end %>
|
30
41
|
|
31
42
|
<% if col.not_null %>
|
32
|
-
<%= "assert(representation.valueForKey(
|
43
|
+
<%= "assert(representation.valueForKey(\"#{col.name}\") != nil, \"Expected #{col.name} to not be nil.\")" %>
|
33
44
|
|
34
45
|
<% end %>
|
35
46
|
<% end %>
|
36
47
|
}
|
37
48
|
|
38
|
-
class func collection(response response: NSHTTPURLResponse, representation: AnyObject) -> [<%= @class_name %>] {
|
39
|
-
let xarray = representation as! [AnyObject]
|
40
|
-
let mapped:[<%= @class_name%>?] = xarray.map({ <%= @class_name%>(response: response, representation: $0) })
|
41
|
-
return mapped.filter({ (element:<%= @class_name %>?) -> Bool in
|
42
|
-
if let _ = element {
|
43
|
-
return true
|
44
|
-
}
|
45
|
-
return false
|
46
|
-
}).map({ (element) -> <%= @class_name%> in
|
47
|
-
return element!
|
48
|
-
})
|
49
|
-
}
|
50
|
-
|
51
49
|
func toDict() -> [String: AnyObject] {
|
52
50
|
let dict:[String:AnyObject?] = [
|
53
51
|
<% @columns.each do |col| %>
|
54
52
|
<% line = "" %>
|
55
53
|
<% if col.type == "datetime" %>
|
56
|
-
<% line = "
|
54
|
+
<% line = "\"#{col.name}\":#{col.formatted_name}.railsFriendly()" %>
|
57
55
|
<% else %>
|
58
|
-
<% line = "
|
56
|
+
<% line = "\"#{col.name}\":#{col.formatted_name}" %>
|
59
57
|
<% end %>
|
60
58
|
<% line += "," if col != @columns.last %>
|
61
59
|
<%= line %>
|