ntq_tools 0.3.1 → 0.4.1

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
  SHA256:
3
- metadata.gz: c5c6201f78773fe0427ef8b4329405e9eb2d8fef626ef26cd5800a123560856c
4
- data.tar.gz: c63e87a37de15a6f5165713e4aef872cf8e7891e033b52e277c8cbfe04e9aed9
3
+ metadata.gz: 57781cd3327d2e0c9a4934e818210a94a5869680d6ca88f17920e627a8bcc49b
4
+ data.tar.gz: aef6ae2230214af398d8a60254430478841d5a83400fe9b80d57764209cdaaad
5
5
  SHA512:
6
- metadata.gz: 0ed2ae3fc896d028160cd65f652ceebe398b97ab874ae910d80c2935bec88dbd1fe2529519585e1003bed8b6e0f4614027c205b6602b02b46f037efda9a9c074
7
- data.tar.gz: 7aaa088106b37e07cbd5cb600f968485ca6dc1d6ba97563e22bf878a7551c37e66713b97e2771288399b05243d76b31deb58e2d52b25179ab183fb627150bc35
6
+ metadata.gz: 23710b7d19138ae83c21ea05db99511ff32fd68fd9541d1442d06f926e392922731a2adccb17949920ec6f945d81e003bb09abd70c475d5a0b77d8c96251cfbb
7
+ data.tar.gz: 18c0103de806aaa82b170bf882c875647c18ac1e855913b0b3ae352a2dae3cf0db1a6b316776c2cfda2a5418128accc7b4fe2b23eea579cf2f70d2b85cc7a13f
@@ -20,6 +20,10 @@ module NtqTools
20
20
  render json: { data: true }, status: 200
21
21
  end
22
22
 
23
+ def refresh
24
+ if defined?(ReactOnRails) system "bundle exec rake react_on_rails:locale"
25
+ end
26
+
23
27
  private
24
28
 
25
29
  def check_presence_of_key
data/config/routes.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  NtqTools::Engine.routes.draw do
2
2
  resource :translation, only: [:update, :show]
3
+ get '/translation/refresh' => "translations#refresh"
3
4
 
4
5
  if NtqTools.impersonation_enabled && NtqTools.impersonation_user_models.any? && defined?(Devise)
5
6
  get '/impersonation/users' => "impersonation#index"
@@ -6,6 +6,8 @@ module NtqTools
6
6
 
7
7
  def create_type_file
8
8
  singular_name = plural_name.singularize
9
+ context_name = plural_name.camelcase
10
+ class_name = singular_name.camelcase
9
11
  return unless defined?(class_name.constantize) && class_name.constantize.respond_to?(:columns_hash)
10
12
 
11
13
  definition = []
@@ -59,16 +61,16 @@ module NtqTools
59
61
  associations = []
60
62
  %i[belongs_to has_one].each do |association_type|
61
63
  class_name.constantize.reflect_on_all_associations(association_type).each do |asso|
62
- class_name = asso.options.dig(:class_name) || asso.name.to_s.singularize.camelcase
63
- associations << "field :#{asso.name}, Types::#{class_name}Type"
64
+ asso_class_name = asso.options.dig(:class_name) || asso.name.to_s.singularize.camelcase
65
+ associations << "field :#{asso.name}, Types::#{asso_class_name.downcase.pluralize.camelcase}::#{asso_class_name}Type"
64
66
  end
65
67
  end
66
68
  [:has_many].each do |association_type|
67
69
  class_name.constantize.reflect_on_all_associations(association_type).each do |asso|
68
- class_name = asso.options.dig(:class_name) || asso.name.to_s.singularize.camelcase
69
- next if class_name == 'PaperTrail::Version'
70
+ asso_class_name = asso.options.dig(:class_name) || asso.name.to_s.singularize.camelcase
71
+ next if asso_class_name == 'PaperTrail::Version'
70
72
 
71
- associations << "field :#{asso.name}, [Types::#{class_name}Type]"
73
+ associations << "field :#{asso.name}, [Types::#{asso_class_name.downcase.pluralize.camelcase}::#{asso_class_name}Type]"
72
74
  end
73
75
  end
74
76
 
@@ -99,23 +101,15 @@ module InputObject
99
101
  ')}
100
102
  end
101
103
  end
102
- FILE
103
-
104
- # Attributes file
105
- create_file "app/graphql/input_object/search_#{plural_name}_attributes.rb", <<~FILE
106
- module InputObject
107
- class Search#{plural_name.camelcase}Attributes < AttributesInputObject
108
-
109
- end
110
- end
111
104
  FILE
112
105
 
113
106
  # Create mutation
114
107
  create_file "app/graphql/mutations/#{plural_name}/create_#{singular_name}.rb", <<~FILE
115
108
  module Mutations
116
109
  class #{plural_name.camelcase}::Create#{singular_name.camelcase} < BaseMutation
110
+
111
+ field :#{singular_name}, Types::#{plural_name.camelcase}::#{singular_name.camelcase}Type, null: false
117
112
  field :flash_messages, [Types::JsonType], null: false
118
- field :#{singular_name}, Types::#{singular_name.camelcase}Type, null: false
119
113
 
120
114
  argument :attributes, InputObject::#{singular_name.camelcase}Attributes, required: true
121
115
 
@@ -145,8 +139,9 @@ FILE
145
139
  create_file "app/graphql/mutations/#{plural_name}/update_#{singular_name}.rb", <<~FILE
146
140
  module Mutations
147
141
  class #{plural_name.camelcase}::Update#{singular_name.camelcase} < BaseMutation
148
- field :flash_messages, [Types::JsonType], null: false
149
- field :#{singular_name}, Types::#{singular_name.camelcase}Type, null: false
142
+
143
+ field :#{singular_name}, Types::#{plural_name.camelcase}::#{singular_name.camelcase}Type, null: false
144
+ field :flash_messages, [Types::JsonType], null: true
150
145
 
151
146
  argument :id, ID, required: true
152
147
  argument :attributes, InputObject::#{singular_name.camelcase}Attributes, required: true
@@ -178,7 +173,9 @@ FILE
178
173
  create_file "app/graphql/mutations/#{plural_name}/delete_#{singular_name}.rb", <<~FILE
179
174
  module Mutations
180
175
  class #{plural_name.camelcase}::Delete#{singular_name.camelcase} < BaseMutation
181
- field :flash_messages, [Types::JsonType], null: false
176
+
177
+ field :#{singular_name}, Types::#{plural_name.camelcase}::#{singular_name.camelcase}Type
178
+ field :flash_messages, [Types::JsonType], null: true
182
179
 
183
180
  argument :id, ID, required: true
184
181
 
@@ -191,6 +188,7 @@ FILE
191
188
  #{singular_name} = ::#{singular_name.camelcase}.find id
192
189
  #{singular_name}.destroy!
193
190
  {
191
+ #{singular_name}: #{singular_name},
194
192
  flash_messages: [
195
193
  {
196
194
  type: 'success',
@@ -203,6 +201,14 @@ FILE
203
201
  end
204
202
  FILE
205
203
 
204
+ inject_into_file 'app/graphql/types/mutation_type.rb', after: "Types::BaseObject" do <<-FILE
205
+
206
+ field :create_#{singular_name}, mutation: Mutations::#{plural_name.camelcase}::Create#{singular_name.camelcase}
207
+ field :update_#{singular_name}, mutation: Mutations::#{plural_name.camelcase}::Update#{singular_name.camelcase}
208
+ field :delete_#{singular_name}, mutation: Mutations::#{plural_name.camelcase}::Delete#{singular_name.camelcase}
209
+ FILE
210
+ end
211
+
206
212
  puts 'Do you want to create the payload file ? (y/n)'
207
213
  input = $stdin.gets.strip
208
214
  if input == 'y'
@@ -210,12 +216,73 @@ FILE
210
216
  module Types
211
217
  module #{plural_name.camelcase}
212
218
  class #{singular_name.camelcase}ListPayload < BaseObject
213
- field :#{plural_name}, [#{singular_name.camelcase}::#{singular_name.camelcase}Type], null: true
219
+ field :#{plural_name}, [#{plural_name.camelcase}::#{singular_name.camelcase}Type], null: true
214
220
  field :pagination, PaginationType, null: true
215
221
  end
216
222
  end
217
223
  end
218
224
  FILE
225
+
226
+ # Attributes file
227
+ create_file "app/graphql/input_object/search_#{plural_name}_attributes.rb", <<~FILE
228
+ module InputObject
229
+ class Search#{plural_name.camelcase}Attributes < AttributesInputObject
230
+
231
+ end
232
+ end
233
+ FILE
234
+
235
+ if defined?(Interactor)
236
+ create_file "app/interactors/#{plural_name}/search_#{singular_name}.rb", <<-FILE
237
+ module #{context_name}
238
+ class Search#{class_name}
239
+ include Interactor::Organizer
240
+
241
+ organize Get#{class_name}, PaginateRecords
242
+ end
243
+ end
244
+ FILE
245
+
246
+ create_file "app/interactors/#{plural_name}/get_#{singular_name}.rb", <<-FILE
247
+ module #{context_name}
248
+ class Get#{class_name}
249
+ include Interactor
250
+
251
+ def call
252
+ search = context.search || {}
253
+ records = ::#{class_name}.ransack(search).result
254
+ context.records = records
255
+ end
256
+ end
257
+ end
258
+ FILE
259
+ end
260
+
261
+ inject_into_file 'app/graphql/types/query_type.rb', after: "# Fields\n" do <<-FILE
262
+ field :#{plural_name}, Types::#{plural_name.camelcase}::#{singular_name.camelcase}ListPayload do
263
+ argument :search, InputObject::Search#{plural_name.camelcase}Attributes, required: false
264
+ argument :page, Integer, required: false
265
+ argument :per_page, Integer, required: false
266
+ end
267
+ def #{plural_name}(search: {}, page: 1, per_page: 25)
268
+ ctx = ::#{plural_name.camelcase}::Search#{singular_name.camelcase}.call(search: search, pagination_params: { page: page, per_page: per_page })
269
+ {
270
+ #{plural_name}: ctx.records,
271
+ pagination: ctx.pagination
272
+ }
273
+ end\n
274
+ FILE
275
+ end
276
+
277
+ inject_into_file 'app/graphql/types/query_type.rb', after: "# Fields\n" do <<-FILE
278
+ field :#{singular_name}, Types::#{plural_name.camelcase}::#{singular_name.camelcase}Type do
279
+ argument :id, ID, required: true
280
+ end
281
+ def #{singular_name}(id:)
282
+ ::#{singular_name.camelcase}.find(id)
283
+ end\n
284
+ FILE
285
+ end
219
286
  end
220
287
  end
221
288
  end
@@ -1,3 +1,3 @@
1
1
  module NtqTools
2
- VERSION = "0.3.1"
2
+ VERSION = "0.4.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ntq_tools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-02-28 00:00:00.000000000 Z
11
+ date: 2023-03-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails