ibrain-core 0.4.2 → 0.4.5
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/mutations/base_mutation.rb +29 -3
- data/lib/generators/ibrain/graphql/templates/mutation.erb +24 -3
- data/lib/ibrain/core/version.rb +2 -2
- data/lib/ibrain/core.rb +0 -1
- data/lib/ibrain_core.rb +7 -1
- metadata +2 -17
- data/config/initializers/friendly_id.rb +0 -87
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e0dfff268b752582b0733cd99f43f0784e20061a2898e29a0c779000e7a07cce
|
4
|
+
data.tar.gz: b42ec5acdd8014ea314e3adacf6bbe6b470720d30aafa84d3b729efbc2d9f913
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e618a908b94991ade401094a790c46815421f752b451ba481626075860723f059a8d9413b586f8ffe39fd9234b671ee264a500eb0b4de5fe9941a4f610ac6ba6
|
7
|
+
data.tar.gz: 1e0ed241b8efc3c4f3545b88513d300a93702cbc7b65401764e562d9ec4322f84f2ae479b19247f212581cc43d6b40ab90163e7b5a3d5548f702c7a981fb63eb
|
@@ -11,13 +11,17 @@ module Ibrain
|
|
11
11
|
argument :attribute, Types::AttributeType, required: false
|
12
12
|
argument :attributes, [Types::AttributeType], required: false
|
13
13
|
|
14
|
-
def
|
15
|
-
@params =
|
14
|
+
def ready?(args)
|
15
|
+
@params = ActionController::Parameters.new(
|
16
|
+
args.to_h.with_indifferent_access.transform_keys(&:underscore)
|
17
|
+
)
|
18
|
+
@resource = load_resource
|
19
|
+
true
|
16
20
|
end
|
17
21
|
|
18
22
|
protected
|
19
23
|
|
20
|
-
attr_reader :params
|
24
|
+
attr_reader :params, :resource
|
21
25
|
|
22
26
|
def upload_permitted
|
23
27
|
%i[content_type headers original_filename tempfile]
|
@@ -42,6 +46,28 @@ module Ibrain
|
|
42
46
|
def request
|
43
47
|
context[:request]
|
44
48
|
end
|
49
|
+
|
50
|
+
def graphql_return
|
51
|
+
{
|
52
|
+
returning: resource.reload
|
53
|
+
}
|
54
|
+
end
|
55
|
+
|
56
|
+
def success_response
|
57
|
+
{
|
58
|
+
success: true
|
59
|
+
}
|
60
|
+
end
|
61
|
+
|
62
|
+
def id_from_params
|
63
|
+
params[:id]
|
64
|
+
end
|
65
|
+
|
66
|
+
def attribute_params
|
67
|
+
params[:attributes].to_params
|
68
|
+
rescue StandardError
|
69
|
+
ActionController::Parameters.new({})
|
70
|
+
end
|
45
71
|
end
|
46
72
|
end
|
47
73
|
end
|
@@ -7,16 +7,37 @@ module Mutations
|
|
7
7
|
# description
|
8
8
|
|
9
9
|
# TODO: define return fields
|
10
|
-
field
|
10
|
+
field :returning, Types::Objects::<%= model_name %>Type, null: true, description: 'Record Type for mutation response'
|
11
11
|
|
12
12
|
# TODO: define arguments
|
13
13
|
# argument :name, String, required: true
|
14
|
-
|
14
|
+
argument :attributes, Types::Attributes::<%= model_name %>Input, required: true
|
15
|
+
# argument :id, ID, required: true
|
15
16
|
|
16
17
|
# TODO: define resolve method
|
17
18
|
def resolve(args)
|
18
19
|
# TODO: define logic inside repository
|
19
|
-
# Something like
|
20
|
+
# Something like
|
21
|
+
# if resource.blank?
|
22
|
+
# raise GraphQL::ExecutionError, I18n.t("activerecord.errors.models.job.attributes.id.could_not_find")
|
23
|
+
# end
|
24
|
+
|
25
|
+
# repo.update(normalize_parameters)
|
26
|
+
graphql_return
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def normalize_parameters
|
32
|
+
# attribute_params.permit(:name, :status)
|
33
|
+
end
|
34
|
+
|
35
|
+
def load_resource
|
36
|
+
# <%= model_name %>.find_by(id: id_from_params)
|
37
|
+
end
|
38
|
+
|
39
|
+
def repo
|
40
|
+
# <%= model_name %>Repository.new(current_user, resource)
|
20
41
|
end
|
21
42
|
end
|
22
43
|
end
|
data/lib/ibrain/core/version.rb
CHANGED
data/lib/ibrain/core.rb
CHANGED
data/lib/ibrain_core.rb
CHANGED
@@ -1,3 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "zeitwerk"
|
4
|
+
loader = Zeitwerk::Loader.new
|
5
|
+
loader.tag = File.basename(__FILE__, ".rb")
|
6
|
+
loader.inflector = Zeitwerk::GemInflector.new(__FILE__)
|
7
|
+
loader.enable_reloading
|
8
|
+
loader.setup
|
9
|
+
loader.reload
|
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.4.
|
4
|
+
version: 0.4.5
|
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-09-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord-session_store
|
@@ -66,20 +66,6 @@ dependencies:
|
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: friendly_id
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
73
|
-
- - ">="
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: '0'
|
76
|
-
type: :runtime
|
77
|
-
prerelease: false
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - ">="
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: '0'
|
83
69
|
- !ruby/object:Gem::Dependency
|
84
70
|
name: gem-release
|
85
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -227,7 +213,6 @@ files:
|
|
227
213
|
- app/models/ibrain/role.rb
|
228
214
|
- app/models/ibrain/role_user.rb
|
229
215
|
- app/repositories/ibrain/base_repository.rb
|
230
|
-
- config/initializers/friendly_id.rb
|
231
216
|
- config/locales/en.yml
|
232
217
|
- config/locales/jp.yml
|
233
218
|
- config/locales/vi.yml
|
@@ -1,87 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# FriendlyId Global Configuration
|
4
|
-
#
|
5
|
-
# Use this to set up shared configuration options for your entire application.
|
6
|
-
# Any of the configuration options shown here can also be applied to single
|
7
|
-
# models by passing arguments to the `friendly_id` class method or defining
|
8
|
-
# methods in your model.
|
9
|
-
#
|
10
|
-
# To learn more, check out the guide:
|
11
|
-
#
|
12
|
-
# http://norman.github.io/friendly_id/file.Guide.html
|
13
|
-
|
14
|
-
FriendlyId.defaults do |config|
|
15
|
-
# ## Reserved Words
|
16
|
-
#
|
17
|
-
# Some words could conflict with Rails's routes when used as slugs, or are
|
18
|
-
# undesirable to allow as slugs. Edit this list as needed for your app.
|
19
|
-
config.use :reserved
|
20
|
-
|
21
|
-
# ## Friendly Finders
|
22
|
-
#
|
23
|
-
# Uncomment this to use friendly finders in all models. By default, if
|
24
|
-
# you wish to find a record by its friendly id, you must do:
|
25
|
-
#
|
26
|
-
# MyModel.friendly.find('foo')
|
27
|
-
#
|
28
|
-
# If you uncomment this, you can do:
|
29
|
-
#
|
30
|
-
# MyModel.find('foo')
|
31
|
-
#
|
32
|
-
# This is significantly more convenient but may not be appropriate for
|
33
|
-
# all applications, so you must explicity opt-in to this behavior. You can
|
34
|
-
# always also configure it on a per-model basis if you prefer.
|
35
|
-
#
|
36
|
-
# Something else to consider is that using the :finders addon boosts
|
37
|
-
# performance because it will avoid Rails-internal code that makes runtime
|
38
|
-
# calls to `Module.extend`.
|
39
|
-
#
|
40
|
-
# config.use :finders
|
41
|
-
#
|
42
|
-
# ## Slugs
|
43
|
-
#
|
44
|
-
# Most applications will use the :slugged module everywhere. If you wish
|
45
|
-
# to do so, uncomment the following line.
|
46
|
-
#
|
47
|
-
# config.use :slugged
|
48
|
-
#
|
49
|
-
# By default, FriendlyId's :slugged addon expects the slug column to be named
|
50
|
-
# 'slug', but you can change it if you wish.
|
51
|
-
#
|
52
|
-
# config.slug_column = 'slug'
|
53
|
-
#
|
54
|
-
# When FriendlyId can not generate a unique ID from your base method, it appends
|
55
|
-
# a UUID, separated by a single dash. You can configure the character used as the
|
56
|
-
# separator. If you're upgrading from FriendlyId 4, you may wish to replace this
|
57
|
-
# with two dashes.
|
58
|
-
#
|
59
|
-
# config.sequence_separator = '-'
|
60
|
-
#
|
61
|
-
# ## Tips and Tricks
|
62
|
-
#
|
63
|
-
# ### Controlling when slugs are generated
|
64
|
-
#
|
65
|
-
# As of FriendlyId 5.0, new slugs are generated only when the slug field is
|
66
|
-
# nil, but if you're using a column as your base method can change this
|
67
|
-
# behavior by overriding the `should_generate_new_friendly_id` method that
|
68
|
-
# FriendlyId adds to your model. The change below makes FriendlyId 5.0 behave
|
69
|
-
# more like 4.0.
|
70
|
-
#
|
71
|
-
# config.use Module.new {
|
72
|
-
# def should_generate_new_friendly_id?
|
73
|
-
# slug.blank? || <your_column_name_here>_changed?
|
74
|
-
# end
|
75
|
-
# }
|
76
|
-
#
|
77
|
-
# FriendlyId uses Rails's `parameterize` method to generate slugs, but for
|
78
|
-
# languages that don't use the Roman alphabet, that's not usually suffient. Here
|
79
|
-
# we use the Babosa library to transliterate Russian Cyrillic slugs to ASCII. If
|
80
|
-
# you use this, don't forget to add "babosa" to your Gemfile.
|
81
|
-
#
|
82
|
-
# config.use Module.new {
|
83
|
-
# def normalize_friendly_id(text)
|
84
|
-
# text.to_slug.normalize! transliterations: [:russian, :latin]
|
85
|
-
# end
|
86
|
-
# }
|
87
|
-
end
|