ibrain-core 0.5.5 → 0.5.7
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 +4 -4
- data/app/graphql/ibrain/extentions/active_required.rb +2 -1
- data/app/graphql/ibrain/loaders/association_count_loader.rb +27 -0
- data/app/graphql/ibrain/loaders/count_loader.rb +20 -0
- data/app/graphql/ibrain/types/base_api_field.rb +5 -1
- data/app/graphql/ibrain/types/base_object.rb +8 -0
- data/app/services/ibrain/mailer_service.rb +8 -0
- data/lib/generators/ibrain/graphql/templates/object.erb +7 -10
- data/lib/generators/ibrain/graphql/type_generator.rb +4 -0
- data/lib/generators/ibrain/install/templates/config/initializers/ibrain.rb.tt +3 -0
- data/lib/ibrain/app_configuration.rb +2 -0
- data/lib/ibrain/core/version.rb +1 -5
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f191aab54d45f3806d2c2f3cddcc3b31fe5d9e8e4f845ef3761a097ffa588b90
|
4
|
+
data.tar.gz: '08030f9583b5d32b5d173e2b5d3a913b665b2637547faf8c90d53e70cd43524c'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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)
|
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
|
@@ -1,15 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
<% module_namespacing_when_supported do -%>
|
4
|
-
|
5
|
-
|
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
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
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]
|
@@ -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
|
data/lib/ibrain/core/version.rb
CHANGED
@@ -1,16 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Ibrain
|
4
|
-
VERSION = "0.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.
|
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-
|
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
|