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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 968e10d71957f4b24eb1e11ce85609dd486760e6
4
- data.tar.gz: d020859c17b938ce7f25e2cb83b45c5ecd459265
3
+ metadata.gz: 1b0328f5b75a2159b36a2496d6ad8da3b377e76e
4
+ data.tar.gz: 1a2720d759048ecd1f54f6289f7bd98a340891cf
5
5
  SHA512:
6
- metadata.gz: 181a3875a19a9db0b6180f2a820b9746cd8e1605c5faa5eb0c67cc823dc11ff64319235fc093589af562d34990ffd064973ed6f2840b6f51791fc6c4c9f4e375
7
- data.tar.gz: fa2daca4f1a57b67cee3cc9600f4137f59f477e918d3c58c964e881c321c9a0cc562a480238969452355f1a23cb78ecca4e935ecbb08f89a95bc793ffd4cf82d
6
+ metadata.gz: d54ca4fb299280000571575fe970bcba2f0354656bd7a83fde5c22199cfc4e7f382a8e3398101d5e87673b5a80912d4a760fdd6ce82e149c51cd93e95a0c35b0
7
+ data.tar.gz: 4c236a8870a3480ae941b8b21fe010c622979609d30a9de0a36b1c5c612bf3ff463628d7c28bb3a2d7fbb2013e9f32a7a9cf714f15d8d52435b93ca50e154f3c
@@ -20,4 +20,4 @@ RailsToSwift.bootstrap_rake
20
20
 
21
21
  RailsToSwift.eager_load()
22
22
 
23
- SwiftModels.create_model_files
23
+ SwiftModels.create_model_files({classified_sort: true})
@@ -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
- timestamps << c
148
- elsif c.name[-3,3].eql?("_id")
149
- associations << c
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, timestamps, associations].each {|a| a.sort_by!(&:name) }
154
+ [rest_cols].each {|a| a.sort_by!(&:name) }
155
155
 
156
- return ([id] << rest_cols << timestamps << associations).flatten
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
- <%= "self.#{col.formatted_name} = (representation.valueForKey('#{col.name}') as? String) ?? ''" %>
31
+ <%= "#{col.formatted_name} = (representation.valueForKey(\"#{col.name}\") as? String) ?? \"\"" %>
21
32
  <% elsif col.type == "integer" %>
22
- <%= "self.#{col.formatted_name} = (representation.valueForKey('#{col.name}') as? Int) ?? -1" %>
33
+ <%= "#{col.formatted_name} = (representation.valueForKey(\"#{col.name}\") as? Int) ?? -1" %>
23
34
  <% elsif col.type == "float" %>
24
- <%= "self.#{col.formatted_name} = (representation.valueForKey('#{col.name}') as? Float) ?? -1.0" %>
35
+ <%= "#{col.formatted_name} = (representation.valueForKey(\"#{col.name}\") as? Float) ?? -1.0" %>
25
36
  <% elsif col.type == "datetime" %>
26
- <%= "self.#{col.formatted_name} = NSDate.fromRails(representation.valueForKey('#{col.name}') as? String ?? '')" %>
37
+ <%= "#{col.formatted_name} = NSDate.fromRails(representation.valueForKey(\"#{col.name}\") as? String ?? \"\")" %>
27
38
  <% elsif col.type == "text" %>
28
- <%= "self.#{col.formatted_name} = (representation.valueForKey('#{col.name}') as? String) ?? ''" %>
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('#{col.name}') != nil, 'Expected #{col.name} to not be nil.')" %>
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 = "'#{col.name}':#{col.formatted_name}.railsFriendly()" %>
54
+ <% line = "\"#{col.name}\":#{col.formatted_name}.railsFriendly()" %>
57
55
  <% else %>
58
- <% line = "'#{col.name}':#{col.formatted_name}" %>
56
+ <% line = "\"#{col.name}\":#{col.formatted_name}" %>
59
57
  <% end %>
60
58
  <% line += "," if col != @columns.last %>
61
59
  <%= line %>
@@ -1,3 +1,3 @@
1
1
  module RailsToSwift
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_to_swift
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josh Juncker