ibrain-core 0.5.5 → 0.5.7

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: a4efce65a5ebfdbbd09e276c87e01399cf4f7d68a90555c1dcde1031fc9d59ee
4
- data.tar.gz: 3cc3a8efa0ed9d585fbf63433b65f8fb4525364fa4ed63abdc9f15335f880f62
3
+ metadata.gz: f191aab54d45f3806d2c2f3cddcc3b31fe5d9e8e4f845ef3761a097ffa588b90
4
+ data.tar.gz: '08030f9583b5d32b5d173e2b5d3a913b665b2637547faf8c90d53e70cd43524c'
5
5
  SHA512:
6
- metadata.gz: f37e88b7c92780d9e1f092e1f9275fefb49a9f34cf6f34e7a06021301a7198d4d1d0a97313e938b87d7c01f460336690c7e22530a9846f1d9b50a53c232917bd
7
- data.tar.gz: 2271a8863458476386fa74cf7548add69f44e734cd248e603d2de54225c76b373abbda4e8b789a3760c271eb81a0d4c74c7c46efc2266de65a9464849544c03f
6
+ metadata.gz: d4f80dcef1a20a8caeec9646d55dc965710b44b64b8ad7d9ba7dd63ca5a3673496dca9b10407ea7d5bc15cdf7f2d636d5bd206807e351208e16b39c9c08ad891
7
+ data.tar.gz: be236a9a75d62f231609bf493447330075a601a2a2495a24f834ca05c5b8565d62347dfaa50776d24fb1f5bc3873cd19c2bb161c631d48dfeca85adc33a0d285
@@ -13,7 +13,8 @@ module Ibrain
13
13
  private
14
14
 
15
15
  def is_activated(object)
16
- object.try(:context).try(:fetch, :current_user, nil).blank? && options.try(:fetch, :session_required, false)
16
+ current_user = object.try(:context).try(:fetch, :current_user, nil)
17
+ current_user.try(:is_activated?) && options.try(:fetch, :active_required, false)
17
18
  end
18
19
  end
19
20
  end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ibrain
4
+ module Loaders
5
+ class AssociationCountLoader < GraphQL::Batch::Loader
6
+ def initialize(model, association_name)
7
+ super()
8
+ @model = model
9
+ @association_name = association_name
10
+ end
11
+
12
+ def perform(records)
13
+ reflection = @model.reflect_on_association(@association_name)
14
+ reflection.check_preloadable!
15
+
16
+ klass = reflection.klass
17
+ field = reflection.join_primary_key
18
+ counts = klass.unscoped.where(field => records).group(field).count
19
+
20
+ records.each do |record|
21
+ record_key = record[reflection.active_record_primary_key]
22
+ fulfill(record, counts[record_key] || 0)
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ibrain
4
+ module Loaders
5
+ class CountLoader < GraphQL::Batch::Loader
6
+ def initialize(model, field)
7
+ super()
8
+ @model = model
9
+ @field = field
10
+ end
11
+
12
+ def perform(ids)
13
+ counts = @model.unscoped.where(@field => ids).group(@field).count
14
+
15
+ counts.each { |id, count| fulfill(id, count) }
16
+ ids.each { |id| fulfill(id, 0) unless fulfilled?(id) }
17
+ end
18
+ end
19
+ end
20
+ end
@@ -5,11 +5,15 @@ module Ibrain
5
5
  class BaseApiField < GraphQL::Schema::Field
6
6
  argument_class ::Ibrain::Types::BaseArgument
7
7
 
8
- def initialize(*args, session_required: true, roles: nil, **kwargs, &block)
8
+ def initialize(*args, session_required: true, roles: nil, active_required: true, **kwargs, &block)
9
9
  super(*args, camelize: false, **kwargs, &block)
10
10
 
11
11
  extension(Ibrain::Extentions::SessionRequired, session_required: session_required) if session_required
12
12
  extension(Ibrain::Extentions::Roles, roles: roles) if roles
13
+
14
+ if ::Ibrain.config.is_activated_account_require && active_required
15
+ extension(Ibrain::Extentions::ActiveRequired)
16
+ end
13
17
  end
14
18
  end
15
19
  end
@@ -24,6 +24,14 @@ module Ibrain
24
24
  def current_user
25
25
  context.try(:fetch, :current_user)
26
26
  end
27
+
28
+ def association_count_loader
29
+ Ibrain::Loaders::AssociationCountLoader
30
+ end
31
+
32
+ def count_loader
33
+ Ibrain::Loaders::CountLoader
34
+ end
27
35
  end
28
36
  end
29
37
  end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ibrain
4
+ class MailerService
5
+ def initialize
6
+ end
7
+ end
8
+ end
@@ -1,15 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  <% module_namespacing_when_supported do -%>
4
- module Types
5
- module Objects
6
- class <%= type_ruby_name.split('::')[-1] %> < Ibrain::Types::BaseType
7
- implements Ibrain::Interfaces::RecordInterface
4
+ class Types::Objects::<%= type_ruby_name.split('::')[-1] %> < Ibrain::Types::BaseObject
5
+ implements Ibrain::Interfaces::RecordInterface
8
6
 
9
- description '<%= type_ruby_name.split('::')[-1] %>'
10
-
11
- <% normalized_fields.each do |f| %> <%= f.to_ruby %>
12
- <% end %>end
13
- end
14
- end
7
+ description '<%= type_ruby_name.split('::')[-1] %>'
8
+ graphql_name <%= type_model_name %>.table_name
9
+
10
+ <% normalized_fields.each do |f| %> <%= f.to_ruby %>
11
+ <% end %>end
15
12
  <% end -%>
@@ -66,6 +66,10 @@ module Ibrain
66
66
  @type_ruby_name ||= self.class.normalize_type_expression(type_name, mode: :ruby)[0]
67
67
  end
68
68
 
69
+ def type_model_name
70
+ @type_model_name ||= type_name.camelize
71
+ end
72
+
69
73
  # @return [String] The user-provided type name, as a GraphQL name
70
74
  def type_graphql_name
71
75
  @type_graphql_name ||= self.class.normalize_type_expression(type_name, mode: :graphql)[0]
@@ -53,6 +53,9 @@ Ibrain.config do |config|
53
53
 
54
54
  # For auto append mutation to graphql
55
55
  config.is_auto_append_mutation = true
56
+
57
+ # Enable require active
58
+ config.is_activated_account_require = false
56
59
  end
57
60
 
58
61
  <% if defined?(Ibrain::Api::Engine) -%>
@@ -57,6 +57,8 @@ module Ibrain
57
57
 
58
58
  preference :is_auto_append_mutation, :boolean, default: true
59
59
 
60
+ preference :is_activated_account_require, :boolean, default: false
61
+
60
62
  def static_model_preferences
61
63
  @static_model_preferences ||= Ibrain::Preferences::StaticModelPreferences.new
62
64
  end
@@ -1,16 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Ibrain
4
- VERSION = "0.5.5"
4
+ VERSION = "0.5.7"
5
5
 
6
6
  def self.ibrain_version
7
7
  VERSION
8
8
  end
9
9
 
10
- def self.previous_ibrain_minor_version
11
- '0.5.4'
12
- end
13
-
14
10
  def self.ibrain_gem_version
15
11
  Gem::Version.new(ibrain_version)
16
12
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ibrain-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.5
4
+ version: 0.5.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tai Nguyen Van
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-09-22 00:00:00.000000000 Z
11
+ date: 2022-10-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord-session_store
@@ -173,7 +173,9 @@ files:
173
173
  - app/graphql/ibrain/interfaces/person_interface.rb
174
174
  - app/graphql/ibrain/interfaces/record_interface.rb
175
175
  - app/graphql/ibrain/lazy/base.rb
176
+ - app/graphql/ibrain/loaders/association_count_loader.rb
176
177
  - app/graphql/ibrain/loaders/association_loader.rb
178
+ - app/graphql/ibrain/loaders/count_loader.rb
177
179
  - app/graphql/ibrain/log_query_depth.rb
178
180
  - app/graphql/ibrain/mutations/base_mutation.rb
179
181
  - app/graphql/ibrain/policies/base_policy.rb
@@ -214,6 +216,7 @@ files:
214
216
  - app/models/ibrain/role.rb
215
217
  - app/models/ibrain/role_user.rb
216
218
  - app/repositories/ibrain/base_repository.rb
219
+ - app/services/ibrain/mailer_service.rb
217
220
  - config/locales/en.yml
218
221
  - config/locales/jp.yml
219
222
  - config/locales/vi.yml