ibrain-core 0.5.6 → 0.5.8
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/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 +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c74180715e26a0b7365da263cc926c968a89176c3b80a7b70233839c8ac971f3
|
4
|
+
data.tar.gz: 8f74dd650002174ec4311e83976c98ececf292b2b4e1179fd6c8bc6835ac35f3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f614df628d2a7ed54a25074acb7c5268d98c26a62b61045b9a6c2f33e0984318e491a5a4228bff5a65403b35e0a8edb571dbf3d1a665a47cb0f2748b17770bac
|
7
|
+
data.tar.gz: 37c7d65e40af2ca14a814a9d73e0ac074c78cb6a626ef01e002bb56b34a565802f1cc80d1b6ae23baba67901e2e8e493960877340604b4468fe100db4d171252
|
@@ -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_require_activated_account && active_required
|
15
|
+
extension(Ibrain::Extentions::ActiveRequired)
|
16
|
+
end
|
13
17
|
end
|
14
18
|
end
|
15
19
|
end
|
@@ -57,6 +57,8 @@ module Ibrain
|
|
57
57
|
|
58
58
|
preference :is_auto_append_mutation, :boolean, default: true
|
59
59
|
|
60
|
+
preference :is_require_activated_account, :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.8"
|
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.5'
|
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.8
|
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-10-
|
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
|