gwtools 0.0.5 → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 43e5aaf57e5a1887d0fd602c416c4727a8163296e5cc0cb23c2a3cd6226bcee7
4
- data.tar.gz: 72c5d96b01cf73ace17487f392213b6c7e9c186b5c9ecfb82d7884cd11c7d4bf
3
+ metadata.gz: 623dae2a8da9444e088fb0775b8490beb07a339d1b48e040b28be4c955fb30b1
4
+ data.tar.gz: 4488cddef5c3b1e72e992f263d38cd23e40951731cc5218aa95e1afb31fb2dd6
5
5
  SHA512:
6
- metadata.gz: 5ed11c0b2efadafa7c0564431fc8191a70451b1601ef4603a13078e10b570326c0802a44044f15e80596c12c75765c29c94712c58974fd492756275843307890
7
- data.tar.gz: f5eda98e671f387149f20d879efa1aaf5698b7c0544b1224c07f52d50200388daff4fb1171755b7947ce700826929a973d5057163e9efdb1d238919770f5c156
6
+ metadata.gz: c52c6bffb2ff6816c726ab1c6d13fc7430e8d2e7b07c8005683a18b0da6dd7a1c3a9d8b49251234f4285067b7cb3aab92df6255e01297143ce6c942f253d2338
7
+ data.tar.gz: 46e363b7424217396fc8ca484850eea5a9b4a6a7cc7042adf8a812c4203f1943a13c843bfa16104c4931b8ce15fa579820efa2ee56b27540a9a965b3a5570b4c
@@ -32,8 +32,8 @@ module Gwtools
32
32
  # """
33
33
 
34
34
  makeDirAndFile(@url)
35
- # 生成对应Model文件
36
- Generate::Swift.createModelAndRequest(@target_path, @responseJson)
35
+ # # 生成对应Model文件
36
+ # Generate::Swift.createModelAndRequest(@target_path, @responseJson)
37
37
 
38
38
  end
39
39
 
@@ -57,7 +57,7 @@ module Gwtools
57
57
  end
58
58
 
59
59
  # create file
60
- Generate::Swift.createPathFile(dir_path, dir, dirs, index)
60
+ Generate::Swift.createPathFile(dir_path, dir, dirs, index, @httpMethod, @responseJson)
61
61
  end
62
62
  end
63
63
 
@@ -17,7 +17,7 @@ module Gwtools
17
17
  end
18
18
 
19
19
  def validate!
20
- # super TODO: 这里还没检查参数
20
+ help! 'file_path is required.' unless @file_path
21
21
  end
22
22
 
23
23
  def run
@@ -39,8 +39,49 @@ extension <%="#{@api_name}"%> {
39
39
  include(ERB::Util)
40
40
  attr_accessor :api_name, :httpmethod, :prefixPath, :modulePath, :detailPath, :model_name, :model_data
41
41
 
42
+ # 将 erb 文件的一个实例化,绑定到当前的一个对象的上下文
42
43
  def config_file
43
- ERB.new(File.read('../lib/erb/model_req.swift.erb'), nil, '>').result(binding)
44
+ # ERB.new(File.read('restful_url.swift.erb'), nil, '>').result(binding)
45
+ template = <<-ERB
46
+ /// 此文件由代码生成,不要修改任何路径相关参数,仅可对 headerParms 和 parms 做处理
47
+
48
+ import RxSwift
49
+ import GWNetWork
50
+ import GWUserCenterBase
51
+ import SwiftyUserDefaults
52
+ import HandyJSON
53
+
54
+ public extension <%="#{@api_name}"%> {
55
+ <%="#{@model_data}\n"%>
56
+ }
57
+
58
+ public extension <%="#{@api_name}"%> {
59
+ static func <%="#{@httpmethod}"%>(/*custom_params,*/
60
+ isCache: Bool = false,
61
+ isLoading: Bool = false,
62
+ module: String? = nil,
63
+ des: String? = nil) -> Observable<Self.<%="#{@httpmethod}"%><%="#{@model_name}"%>> {
64
+ // ================= 逻辑处理 =================
65
+ let headerParms: [String : String] = [:]
66
+ let parms: [String : Any] = [:]
67
+ // ================= 逻辑处理 =================
68
+
69
+ return GWNetworkManager.request(requestType: .<%="#{@httpmethod}"%>,
70
+ prefixPath: "<%="#{@prefixPath}"%>",
71
+ modulePath: "<%="#{@modulePath}"%>",
72
+ detailPath: "<%="#{@detailPath}"%>",
73
+ parms: parms,
74
+ headerParms: headerParms,
75
+ isCache: isCache,
76
+ isLoading: isLoading,
77
+ module: module,
78
+ des: des)
79
+ .mapHandyJSON(Self.<%="#{@model_name}"%>.self)
80
+
81
+ }
82
+ }
83
+ ERB
84
+ ERB.new(template, nil, '>').result(binding)
44
85
  end
45
86
 
46
87
  def initialize(file_path, api_name, httpmethod, prefixPath, modulePath, detailPath, model_name, model_data)
@@ -58,15 +99,36 @@ extension <%="#{@api_name}"%> {
58
99
  end
59
100
  end
60
101
 
61
- def self.createPathFile(dir_path, dir, dirs, index)
102
+ def self.createPathFile(dir_path, dir, dirs, index, http_method, response_json)
62
103
  if index <= 0
63
104
  return
64
105
  end
65
- PathGenerateConfig.new(
66
- "#{dir_path}.swift",
67
- "AppAPI.#{dirs[0..index-1].join('.')}",
68
- dir
69
- )
106
+ if dir == 'restful'
107
+ puts dir_path
108
+ puts dir
109
+ puts dirs.join('/')
110
+ puts dirs[0..index-1].join('.')
111
+ swift_model = generate_model("Model", response_json)
112
+ ModelReqGenerateConfig.new(
113
+ "#{dir_path}.swift",
114
+ "AppAPI.#{dirs[0..index-1].join('.')}",
115
+ http_method.capitalize,
116
+ 'app-api/api/v1.0',
117
+ 'content',
118
+ '/route/getContentInfo',
119
+ 'GetModel',
120
+ swift_model
121
+ )
122
+
123
+ `swiftformat --swiftversion 5.0 #{dir_path}.swift`
124
+ else
125
+ PathGenerateConfig.new(
126
+ "#{dir_path}.swift",
127
+ "AppAPI.#{dirs[0..index-1].join('.')}",
128
+ dir
129
+ )
130
+ end
131
+
70
132
  end
71
133
 
72
134
  def self.generate_model(name, json_data)
@@ -101,10 +163,10 @@ extension <%="#{@api_name}"%> {
101
163
  swift_model + "}\n"
102
164
  end
103
165
 
104
- def self.createModelAndRequest(target_path, responseJson)
105
- swift_model = generate_model("Model", responseJson)
106
- File.write(target_path + 'Model.swift', swift_model)
107
- end
166
+ # def self.createModelAndRequest(target_path, responseJson)
167
+ # swift_model = generate_model("Model", responseJson)
168
+ # File.write(target_path + 'Model.swift', swift_model)
169
+ # end
108
170
 
109
171
  # 生成 Swift 模型
110
172
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Gwtools
4
- VERSION = "0.0.5"
4
+ VERSION = "0.0.6"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gwtools
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
  - chenglq