ibrain-core 0.1.2 → 0.1.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 +4 -4
- data/app/controllers/ibrain/graphql_controller.rb +1 -1
- data/app/graphql/ibrain/extentions/default_value.rb +0 -2
- data/app/graphql/ibrain/interfaces/record_interface.rb +0 -2
- data/app/graphql/ibrain/resolvers/base_resolver.rb +3 -3
- data/app/graphql/ibrain/types/attribute_type.rb +8 -0
- data/app/graphql/ibrain/types/base_node.rb +1 -1
- data/app/graphql/ibrain/types/base_object.rb +1 -1
- data/app/graphql/ibrain/types/filter_type.rb +0 -1
- data/app/models/ibrain/base.rb +24 -12
- data/app/repositories/ibrain/base_repository.rb +18 -0
- data/lib/generators/ibrain/graphql/core.rb +4 -0
- data/lib/generators/ibrain/graphql/mutation_generator.rb +4 -0
- data/lib/generators/ibrain/graphql/object_generator.rb +7 -0
- data/lib/generators/ibrain/graphql/resolver_generator.rb +4 -0
- data/lib/generators/ibrain/graphql/resolvers_generator.rb +4 -0
- data/lib/generators/ibrain/graphql/templates/aggregate.erb +1 -1
- data/lib/generators/ibrain/graphql/templates/mutation.erb +2 -1
- data/lib/generators/ibrain/graphql/templates/repository.erb +19 -0
- data/lib/generators/ibrain/graphql/templates/resolver.erb +1 -1
- data/lib/generators/ibrain/graphql/templates/resolvers.erb +1 -1
- data/lib/generators/ibrain/install/install_generator.rb +5 -16
- data/lib/generators/ibrain/install/templates/config/initializers/cors.tt +1 -1
- data/lib/generators/ibrain/install/templates/graphql/app_schema.rb.tt +0 -2
- data/lib/generators/ibrain/install/templates/rubocop.yml.tt +19 -2
- data/lib/ibrain/core/controller_helpers/auth.rb +6 -2
- data/lib/ibrain/core/version.rb +2 -2
- 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: f097ac075d8648653298078113ae7d36b8b9058b8a06dd93d450c6c1126ea1fc
|
4
|
+
data.tar.gz: 9dcdccbb0202e258a67d1f7373e2abb329f47fc6e2ad94faccd832e489a19c82
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 49610235d7470b0634732e8f47c40d12d6e80cfeff70fa676b586883e251b2a125367ee34232e49c79456910e679827b1597a16b8aabe1a4dc4266c6d10bbf81
|
7
|
+
data.tar.gz: 137dbd8406dc08d92624cf78e0c8732b31b89507a39372cd0215d2ed6e3514d990f4ab90da097a45861cf351228e9c33af3bb9373561a2a9deab2790c2300e4c
|
@@ -3,9 +3,9 @@
|
|
3
3
|
module Ibrain
|
4
4
|
module Resolvers
|
5
5
|
class BaseResolver < GraphQL::Schema::Resolver
|
6
|
-
argument :filter, Ibrain::Types::FilterType, required: false, default_value: nil
|
7
|
-
argument :limit, Int, required: false, default_value: 10
|
8
|
-
argument :offset, Int, required: false, default_value: 0
|
6
|
+
argument :filter, Ibrain::Types::FilterType, required: false, default_value: nil
|
7
|
+
argument :limit, Int, required: false, default_value: 10
|
8
|
+
argument :offset, Int, required: false, default_value: 0
|
9
9
|
|
10
10
|
def current_user
|
11
11
|
context.fetch(:current_user)
|
data/app/models/ibrain/base.rb
CHANGED
@@ -1,20 +1,18 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
IGNORE_ATTRIBUTES = %w(id created_at updated_at)
|
4
|
+
|
3
5
|
class Ibrain::Base < Ibrain::ApplicationRecord
|
4
6
|
include ActionView::Helpers::DateHelper
|
5
7
|
|
6
8
|
self.abstract_class = true
|
7
9
|
|
8
|
-
def self.adjust_date_for_cdt(datetime)
|
9
|
-
datetime.in_time_zone('UTC')
|
10
|
-
end
|
11
|
-
|
12
10
|
def string_id
|
13
11
|
try(:id).try(:to_s)
|
14
12
|
end
|
15
13
|
|
16
14
|
scope :graphql_ransack, lambda { |params|
|
17
|
-
ransack(params).result
|
15
|
+
ransack(params).result
|
18
16
|
}
|
19
17
|
|
20
18
|
scope :reverse_scope, lambda {
|
@@ -36,12 +34,26 @@ class Ibrain::Base < Ibrain::ApplicationRecord
|
|
36
34
|
time_ago_in_words(created_at)
|
37
35
|
end
|
38
36
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
37
|
+
class << self
|
38
|
+
# Provides a scope that should be included any time data
|
39
|
+
# are fetched with the intention of displaying to the user.
|
40
|
+
#
|
41
|
+
# Allows individual stores to include any active record scopes or joins
|
42
|
+
# when data are displayed.
|
43
|
+
def display_includes
|
44
|
+
where(nil)
|
45
|
+
end
|
46
|
+
|
47
|
+
def paginate(args)
|
48
|
+
limit(args[:limit]).offset(args[:offset])
|
49
|
+
end
|
50
|
+
|
51
|
+
def adjust_date_for_cdt(datetime)
|
52
|
+
datetime.in_time_zone('UTC')
|
53
|
+
end
|
54
|
+
|
55
|
+
def permitted_attributes
|
56
|
+
column_names.reject { |k| IGNORE_ATTRIBUTES.include?(k) }
|
57
|
+
end
|
46
58
|
end
|
47
59
|
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Ibrain
|
4
|
+
class BaseRepository
|
5
|
+
def initialize(current_user, record)
|
6
|
+
@current_user = current_user
|
7
|
+
@record = record
|
8
|
+
end
|
9
|
+
|
10
|
+
attr_reader :current_user, :record
|
11
|
+
|
12
|
+
protected
|
13
|
+
|
14
|
+
def cryptor
|
15
|
+
Ibrain::Encryptor.new
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -36,6 +36,10 @@ module Ibrain
|
|
36
36
|
create_mutation_root_type
|
37
37
|
end
|
38
38
|
|
39
|
+
if options[:model].present?
|
40
|
+
system("bundle exec rails generate ibrain:graphql:object #{options[:model].downcase}")
|
41
|
+
end
|
42
|
+
|
39
43
|
template "mutation.erb", "#{options[:directory]}/mutations/#{file_name}.rb"
|
40
44
|
|
41
45
|
sentinel = /class .*MutationType\s*<\s*[^\s]+?\n/m
|
@@ -29,7 +29,10 @@ module Ibrain
|
|
29
29
|
desc: "Include the Relay Node interface"
|
30
30
|
|
31
31
|
def create_type_file
|
32
|
+
create_dir('app/repositories') unless Dir.exist?('app/repositories')
|
33
|
+
|
32
34
|
template "object.erb", "#{options[:directory]}/types/objects/#{type_file_name}.rb"
|
35
|
+
template "repository.erb", "app/repositories/#{type_name}_repository.rb"
|
33
36
|
end
|
34
37
|
|
35
38
|
def fields
|
@@ -72,6 +75,10 @@ module Ibrain
|
|
72
75
|
false
|
73
76
|
end
|
74
77
|
|
78
|
+
def model_name
|
79
|
+
type_name.capitalize
|
80
|
+
end
|
81
|
+
|
75
82
|
def klass
|
76
83
|
@klass ||= Module.const_get(type_name.camelize)
|
77
84
|
end
|
@@ -20,6 +20,10 @@ module Ibrain
|
|
20
20
|
create_resolver_root_type
|
21
21
|
end
|
22
22
|
|
23
|
+
if options[:model].present?
|
24
|
+
system("bundle exec rails generate ibrain:graphql:object #{options[:model].downcase}")
|
25
|
+
end
|
26
|
+
|
23
27
|
template "resolver.erb", "#{options[:directory]}/resolvers/#{file_name}.rb"
|
24
28
|
|
25
29
|
sentinel = /class .*QueryType\s*<\s*[^\s]+?\n/m
|
@@ -36,6 +36,10 @@ module Ibrain
|
|
36
36
|
create_resolver_root_type
|
37
37
|
end
|
38
38
|
|
39
|
+
if options[:model].present?
|
40
|
+
system("bundle exec rails generate ibrain:graphql:object #{options[:model].downcase}")
|
41
|
+
end
|
42
|
+
|
39
43
|
template "resolvers.erb", "#{options[:directory]}/resolvers/#{file_name}.rb"
|
40
44
|
template "aggregate.erb", "#{options[:directory]}/resolvers/#{file_name}_aggregate.rb"
|
41
45
|
|
@@ -6,7 +6,7 @@ module Resolvers
|
|
6
6
|
description 'Define aggregate to count total records for <%= resolver_name %>'
|
7
7
|
# define resolve method
|
8
8
|
def resolve(args)
|
9
|
-
<%= model_name.capitalize
|
9
|
+
<%= model_name.capitalize %>Repository.aggregate(args)
|
10
10
|
end
|
11
11
|
end
|
12
12
|
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
<% module_namespacing_when_supported do -%>
|
4
|
+
class <%= model_name %>Repository < Ibrain::BaseRepository
|
5
|
+
def initialize(current_user, record = nil)
|
6
|
+
super(current_user, record)
|
7
|
+
end
|
8
|
+
|
9
|
+
class << self
|
10
|
+
def find(args)
|
11
|
+
<%= model_name %>.find args[:id]
|
12
|
+
end
|
13
|
+
|
14
|
+
def aggregate(args)
|
15
|
+
<%= model_name %>.ransack(args[:filter]).result
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
<% end -%>
|
@@ -35,17 +35,6 @@ module Ibrain
|
|
35
35
|
end
|
36
36
|
|
37
37
|
def configure_application
|
38
|
-
application <<-RUBY
|
39
|
-
# Load application's model / class decorators
|
40
|
-
initializer 'ibrain.decorators' do |app|
|
41
|
-
config.to_prepare do
|
42
|
-
Dir.glob(Rails.root.join('app/**/*_decorator*.rb')) do |path|
|
43
|
-
require_dependency(path)
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
RUBY
|
48
|
-
|
49
38
|
if !options[:enforce_available_locales].nil?
|
50
39
|
application <<-RUBY
|
51
40
|
I18n.enforce_available_locales = #{options[:enforce_available_locales]}
|
@@ -66,7 +55,7 @@ module Ibrain
|
|
66
55
|
Would you like to install it? (Y/n)"))
|
67
56
|
|
68
57
|
@plugins_to_be_installed << 'ibrain-auth' unless system('gem list | grep ibrain-auth')
|
69
|
-
@plugin_generators_to_run <<
|
58
|
+
@plugin_generators_to_run << "ibrain:auth:install --with-ridgpole=#{options[:with_ridgepole]}"
|
70
59
|
end
|
71
60
|
end
|
72
61
|
|
@@ -135,10 +124,10 @@ module Ibrain
|
|
135
124
|
|
136
125
|
def add_files
|
137
126
|
template 'config/initializers/ibrain.rb.tt', 'config/initializers/ibrain.rb', { skip: true }
|
138
|
-
template 'config/initializers/cors.tt', 'config/initializers/cors.rb'
|
139
|
-
template 'config/puma.tt', 'config/puma.rb'
|
140
|
-
yml_template 'config/database.tt', 'config/database.yml'
|
141
|
-
template 'rubocop.yml.tt', '.rubocop.yml'
|
127
|
+
template 'config/initializers/cors.tt', 'config/initializers/cors.rb'
|
128
|
+
template 'config/puma.tt', 'config/puma.rb'
|
129
|
+
yml_template 'config/database.tt', 'config/database.yml'
|
130
|
+
template 'rubocop.yml.tt', '.rubocop.yml' if options[:with_rubocop]
|
142
131
|
|
143
132
|
if options[:with_graphql]
|
144
133
|
template 'graphql/app_schema.rb.tt', 'app/graphql/app_schema.rb', { skip: true }
|
@@ -113,6 +113,7 @@ Rails/DynamicFindBy:
|
|
113
113
|
# It's okay to skip model validations to setup a spec.
|
114
114
|
Rails/SkipsModelValidations:
|
115
115
|
Exclude:
|
116
|
+
- db/seeds/**/*.rb
|
116
117
|
- '*/spec/**/*'
|
117
118
|
|
118
119
|
# We use a lot of
|
@@ -277,7 +278,7 @@ Metrics/BlockLength:
|
|
277
278
|
Metrics/CyclomaticComplexity:
|
278
279
|
Enabled: false
|
279
280
|
|
280
|
-
|
281
|
+
Layout/LineLength:
|
281
282
|
Enabled: false
|
282
283
|
|
283
284
|
Metrics/MethodLength:
|
@@ -595,4 +596,20 @@ Gemspec/RequiredRubyVersion:
|
|
595
596
|
Enabled: false
|
596
597
|
|
597
598
|
GraphQL/FieldDescription:
|
598
|
-
Enabled: false
|
599
|
+
Enabled: false
|
600
|
+
|
601
|
+
GraphQL/ObjectDescription:
|
602
|
+
Enabled: true
|
603
|
+
Exclude:
|
604
|
+
- app/graphql/policies/*.rb
|
605
|
+
- app/graphql/*.rb
|
606
|
+
|
607
|
+
GraphQL/ExtractType:
|
608
|
+
Enabled: false
|
609
|
+
|
610
|
+
Rails/UnknownEnv:
|
611
|
+
Environments:
|
612
|
+
- production
|
613
|
+
- development
|
614
|
+
- test
|
615
|
+
- staging
|
@@ -52,11 +52,15 @@ module Ibrain
|
|
52
52
|
# This one will be defined by apps looking to hook into Ibrain
|
53
53
|
# As per authentication_helpers.rb
|
54
54
|
if respond_to?(:ibrain_current_user, true)
|
55
|
-
ibrain_current_user
|
55
|
+
try(:ibrain_current_user)
|
56
56
|
# This one will be defined by Devise
|
57
57
|
elsif respond_to?(:current_ibrain_user, true)
|
58
|
-
current_ibrain_user
|
58
|
+
try(:current_ibrain_user)
|
59
59
|
end
|
60
|
+
rescue StandardError => e
|
61
|
+
Ibrain::Logger.warn e.message.to_s
|
62
|
+
|
63
|
+
nil
|
60
64
|
end
|
61
65
|
end
|
62
66
|
end
|
data/lib/ibrain/core/version.rb
CHANGED
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.1.
|
4
|
+
version: 0.1.6
|
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: 2021-12-
|
11
|
+
date: 2021-12-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord-session_store
|
@@ -183,6 +183,7 @@ files:
|
|
183
183
|
- app/graphql/ibrain/resolvers/base_aggregate.rb
|
184
184
|
- app/graphql/ibrain/resolvers/base_resolver.rb
|
185
185
|
- app/graphql/ibrain/types/aggregate_type.rb
|
186
|
+
- app/graphql/ibrain/types/attribute_type.rb
|
186
187
|
- app/graphql/ibrain/types/base_argument.rb
|
187
188
|
- app/graphql/ibrain/types/base_connection.rb
|
188
189
|
- app/graphql/ibrain/types/base_edge.rb
|
@@ -210,6 +211,7 @@ files:
|
|
210
211
|
- app/models/ibrain/legacy_user.rb
|
211
212
|
- app/models/ibrain/role.rb
|
212
213
|
- app/models/ibrain/role_user.rb
|
214
|
+
- app/repositories/ibrain/base_repository.rb
|
213
215
|
- config/initializers/friendly_id.rb
|
214
216
|
- config/locales/en.yml
|
215
217
|
- config/locales/jp.yml
|
@@ -223,6 +225,7 @@ files:
|
|
223
225
|
- lib/generators/ibrain/graphql/templates/aggregate.erb
|
224
226
|
- lib/generators/ibrain/graphql/templates/mutation.erb
|
225
227
|
- lib/generators/ibrain/graphql/templates/object.erb
|
228
|
+
- lib/generators/ibrain/graphql/templates/repository.erb
|
226
229
|
- lib/generators/ibrain/graphql/templates/resolver.erb
|
227
230
|
- lib/generators/ibrain/graphql/templates/resolvers.erb
|
228
231
|
- lib/generators/ibrain/graphql/type_generator.rb
|