veda-apps 0.0.5 → 0.0.6

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: 0542c96e318ef577026b308353a4c3a5181ebfe4
4
- data.tar.gz: 869a88dcd3f8d51596dde99b529590b045481ed9
3
+ metadata.gz: 56836eca037b3c53214be7ada6488144c465150e
4
+ data.tar.gz: c2db5aea2dc56503fe22b3d3a97ce1e578093269
5
5
  SHA512:
6
- metadata.gz: 908db94bb23955b0554a91db4ed1dabdf23da376dc14ae18aca9a1a40c9b782b64a3b789bef72598bf2f494644a45ccd9a1b7e811bed70f65c4f0261b8e37d34
7
- data.tar.gz: d887d4a00ef5dcf3688d11a25e27798901ffb880daa4a7c6392e4ebc1f3a3c20f03920188f49a2a61b20a0aded02aa23e72182bec8933eb97811623e3a1d2e9f
6
+ metadata.gz: 088e50b34dd94473673660946f746a5f0665699168aea60fc450dac347ad0433dd59ee91e0ca351b725265bf99ece8dd4f89d2bebeaf3aba737086833acecb5f
7
+ data.tar.gz: e6a5eacb2473756d98f5cc8231a7722896d0f6d2cc87b687845b19928196544e31b9adf56fec0cd9f80e80ee1650f99a2347125486a1d521fbf945ad856b4cd8
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- veda-apps (0.0.4)
4
+ veda-apps (0.0.5)
5
5
  gli (= 2.17.1)
6
6
  rest-client
7
7
 
@@ -75,4 +75,4 @@ DEPENDENCIES
75
75
  veda-apps!
76
76
 
77
77
  BUNDLED WITH
78
- 1.14.4
78
+ 1.16.1
data/bin/veda CHANGED
@@ -24,6 +24,7 @@ command :generate do |c|
24
24
  c.desc "Generates model for swift from config file or json file"
25
25
  c.command :model do |m|
26
26
  m.switch [:r, :realm, 'option_to_generate_models_for_realm']
27
+ m.flag ["m", "moya", 'option_to_generate_models_for_Moya_mapper']
27
28
  m.flag [:f, :file, 'file_path_to_json']
28
29
 
29
30
  # creates config.json
@@ -53,12 +54,24 @@ c.command :model do |m|
53
54
  if File.exist?(filepath)
54
55
  puts "creating parser with file #{filepath} and #{options[:realm]}"
55
56
  parser = Parser.new filepath, options[:realm]
56
- parser.parse!
57
+ parser.parseForMoya!
57
58
  else
58
59
  puts "cannot find file: #{filepath}"
59
60
  puts "use: 'veda generate model config' to generate the configuration file at working directory."
60
61
  end
61
- elsif
62
+ elsif options[:m]
63
+ puts "generating moya files"
64
+ filepath = options[:moya]
65
+ puts filepath
66
+ if File.exist?(filepath)
67
+ puts "creating parser with file #{filepath} and #{options[:realm]}"
68
+ parser = Parser.new filepath, options[:realm]
69
+ parser.parseForMoya!
70
+ else
71
+ puts "cannot find file: #{filepath}"
72
+ puts "use: 'veda generate model config' to generate the configuration file at working directory."
73
+ end
74
+ else
62
75
  config_path = Dir.pwd + "/" + "config.json"
63
76
  if File.exist?config_path
64
77
  puts "loading parser with config.json and realm = #{options[:realm]}"
data/lib/parser.rb CHANGED
@@ -4,19 +4,19 @@ require 'uri'
4
4
 
5
5
 
6
6
  class String
7
- def camelize
8
- splitted = self.split('_')
9
- camel_text = splitted[1..-1].collect(&:capitalize).join
10
- camel_text = splitted.first.nil? ? self : (splitted.first + camel_text)
11
- camel_text.unHyphoniezed
12
- end
13
-
14
- def unHyphoniezed
15
- splitted = self.split('-')
16
- camel_text = splitted[1..-1].collect(&:capitalize).join
17
- splitted.first.nil? ? self : (splitted.first + camel_text)
7
+ def camelize
8
+ filtered = self.split('_').select {|v| v != ""}
9
+ camel_text = filtered[1..-1].collect(&:capitalize).join
10
+ camel_text = filtered.first.nil? ? self : (filtered.first + camel_text)
11
+ camel_text.unHyphoniezed
12
+ end
13
+
14
+ def unHyphoniezed
15
+ splitted = self.split('-')
16
+ camel_text = splitted[1..-1].collect(&:capitalize).join
17
+ splitted.first.nil? ? self : (splitted.first + camel_text)
18
+ end
18
19
  end
19
- end
20
20
 
21
21
  class Parser
22
22
  def initialize path, realm=false
@@ -85,36 +85,35 @@ class Parser
85
85
  def generate_attributes_literals json
86
86
  swiftClassAttributes = []
87
87
  swiftClass = ""
88
+ # take all hash
88
89
  if json.is_a? Hash
90
+ # loop on each key value pair
89
91
  json.each do |key, value|
92
+ # if value is not array or hash it is a attribute
90
93
  if !(value.is_a? Array) && !(value.is_a? Hash)
91
- # string = "#{get_attribute_literal_prefix}var #{key}: #{attribute_type value} = #{default_value value}\n"
92
- # swiftClass = swiftClass + string
93
94
  attribute = Attribute.new(key, "#{attribute_type value}")
94
95
  swiftClassAttributes.push(attribute)
95
96
  elsif value.is_a? Hash
96
97
  newSwiftClass = generate_attributes_literals value
97
98
  @parsed.store(key.capitalize.camelize, newSwiftClass)
98
- # string = "#{get_attribute_literal_prefix}var #{key}: #{key.capitalize}?\n"
99
- # swiftClass = swiftClass + string
100
99
  attribute = Attribute.new(key, "#{key}")
101
100
  swiftClassAttributes.push(attribute)
102
101
  elsif value.is_a? Array
103
102
  if value.first.is_a? Hash
104
103
  newSwiftClass = generate_attributes_literals value.first
105
104
  @parsed.store(key.capitalize.camelize, newSwiftClass)
106
- # string = "var #{key}#{get_array_attribute_literal key}\n"
107
- # swiftClass = swiftClass + string
108
105
  attribute = Attribute.new(key, "#{key}", true)
109
106
  swiftClassAttributes.push(attribute)
110
107
  else
111
- # string = "var #{key}: [#{attribute_type value.first}] = []\n"
112
- # swiftClass = swiftClass + string
113
108
  attribute = Attribute.new(key, "#{attribute_type value.first}", true)
114
109
  swiftClassAttributes.push(attribute)
115
110
  end
116
111
  end
117
112
  end
113
+ elsif json.is_a? Array
114
+ if json.first.is_a? Hash
115
+ generate_attributes_literals json.first
116
+ end
118
117
  end
119
118
  # swiftClass
120
119
  swiftClassAttributes
@@ -162,6 +161,11 @@ DEFAULT
162
161
  end
163
162
 
164
163
  class_model = <<-CLASS
164
+ //
165
+ // Created with veda-apps.
166
+ // https://rubygems.org/gems/veda-apps
167
+ //
168
+ import Foundation
165
169
  import ObjectMapper
166
170
  #{@realm? "import RealmSwift\nimport ObjectMapper_Realm" : ""}
167
171
 
@@ -177,6 +181,59 @@ CLASS
177
181
  end
178
182
  end
179
183
 
184
+
185
+ # parser for moya model mapper
186
+ def parseForMoya!
187
+
188
+ swiftClass = generate_attributes_literals @json
189
+ if @json.is_a? Hash
190
+ @parsed.store("Container", swiftClass)
191
+ end
192
+
193
+ @parsed.each do |class_name, attributes|
194
+ attribute_literals = ""
195
+ mapping_literals = ""
196
+ key_literals = ""
197
+ attributes.each do |attribute|
198
+ attribute_literal = ""
199
+ mapping_literal = ""
200
+ key_literal = ""
201
+ if attribute.is_array
202
+ attribute_literal = "\tlet #{attribute.name.camelize}: [#{attribute.type.capitalize}]\n"
203
+ else
204
+ attribute_literal = "\tlet #{attribute.name.camelize}: #{attribute.type.capitalize}\n"
205
+ end
206
+ mapping_literal = "\t\t#{attribute.name.camelize} = try map.from(Key.#{attribute.name.camelize})\n"
207
+ key_literal = "\t\tstatic let #{attribute.name.camelize} = \"#{attribute.name}\"\n"
208
+ attribute_literals += attribute_literal
209
+ mapping_literals += mapping_literal
210
+ key_literals += key_literal
211
+ end
212
+
213
+ class_model = <<-CLASS
214
+ //
215
+ // Created with veda-apps.
216
+ // https://rubygems.org/gems/veda-apps
217
+ //
218
+ import Foundation
219
+ import Moya
220
+ import Mapper
221
+
222
+ struct #{class_name}: Mappable {
223
+ #{attribute_literals}
224
+ \tinit(map: Mapper) throws {
225
+ #{mapping_literals}
226
+ \t}
227
+
228
+ \tstruct Key {
229
+ #{key_literals}
230
+ \t}
231
+ }\n
232
+ CLASS
233
+ create_file class_name, class_model
234
+ end
235
+ end
236
+
180
237
  end
181
238
 
182
239
  class Attribute
data/lib/veda/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Veda
2
- VERSION = '0.0.5'
2
+ VERSION = '0.0.6'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: veda-apps
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shishir sapkota