ibrain-core 0.4.5 → 0.4.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (85) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/ibrain/base_controller.rb +12 -14
  3. data/app/controllers/ibrain/core/graphql_controller.rb +79 -83
  4. data/app/graphql/ibrain/base_schema.rb +50 -52
  5. data/app/graphql/ibrain/extentions/default_value.rb +7 -11
  6. data/app/graphql/ibrain/extentions/roles.rb +15 -20
  7. data/app/graphql/ibrain/extentions/session_required.rb +10 -14
  8. data/app/graphql/ibrain/lazy/base.rb +2 -6
  9. data/app/graphql/ibrain/loaders/association_loader.rb +51 -55
  10. data/app/graphql/ibrain/mutations/base_mutation.rb +52 -56
  11. data/app/graphql/ibrain/policies/base_policy.rb +43 -47
  12. data/app/graphql/ibrain/policies/graphql_policy.rb +2 -6
  13. data/app/graphql/ibrain/resolvers/base_aggregate.rb +6 -10
  14. data/app/graphql/ibrain/resolvers/base_resolver.rb +8 -12
  15. data/app/graphql/ibrain/types/aggregate_type.rb +4 -8
  16. data/app/graphql/ibrain/types/attribute_type.rb +2 -5
  17. data/app/graphql/ibrain/types/base_api_connection.rb +6 -10
  18. data/app/graphql/ibrain/types/base_api_edge.rb +4 -8
  19. data/app/graphql/ibrain/types/base_api_field.rb +7 -11
  20. data/app/graphql/ibrain/types/base_api_object.rb +6 -10
  21. data/app/graphql/ibrain/types/base_argument.rb +3 -7
  22. data/app/graphql/ibrain/types/base_connection.rb +7 -11
  23. data/app/graphql/ibrain/types/base_edge.rb +3 -7
  24. data/app/graphql/ibrain/types/base_enum.rb +1 -5
  25. data/app/graphql/ibrain/types/base_field.rb +6 -10
  26. data/app/graphql/ibrain/types/base_input_object.rb +6 -10
  27. data/app/graphql/ibrain/types/base_interface.rb +5 -9
  28. data/app/graphql/ibrain/types/base_object.rb +12 -16
  29. data/app/graphql/ibrain/types/base_scalar.rb +1 -5
  30. data/app/graphql/ibrain/types/base_type.rb +4 -10
  31. data/app/graphql/ibrain/types/base_union.rb +3 -7
  32. data/app/graphql/ibrain/types/filter_type.rb +1 -5
  33. data/app/graphql/ibrain/types/node_type.rb +4 -8
  34. data/app/graphql/ibrain/util/field_combiner.rb +5 -9
  35. data/app/graphql/ibrain/util/query_combiner.rb +4 -8
  36. data/app/models/concerns/ibrain/soft_deletable.rb +6 -8
  37. data/app/models/concerns/ibrain/user_api_authentication.rb +14 -16
  38. data/app/models/concerns/ibrain/user_methods.rb +11 -13
  39. data/app/models/ibrain/ability.rb +31 -32
  40. data/app/models/ibrain/aggregate.rb +5 -7
  41. data/app/models/ibrain/application_record.rb +2 -4
  42. data/app/models/ibrain/legacy_user.rb +7 -13
  43. data/app/models/ibrain/role.rb +6 -8
  44. data/app/models/ibrain/role_user.rb +8 -10
  45. data/app/repositories/ibrain/base_repository.rb +9 -11
  46. data/lib/generators/ibrain/core/model_generator.rb +17 -21
  47. data/lib/generators/ibrain/graphql/core.rb +55 -59
  48. data/lib/generators/ibrain/graphql/mutation_generator.rb +58 -66
  49. data/lib/generators/ibrain/graphql/object_generator.rb +58 -70
  50. data/lib/generators/ibrain/graphql/resolver_generator.rb +17 -25
  51. data/lib/generators/ibrain/graphql/resolvers_generator.rb +59 -67
  52. data/lib/generators/ibrain/graphql/templates/aggregate.erb +5 -7
  53. data/lib/generators/ibrain/graphql/templates/input.erb +5 -9
  54. data/lib/generators/ibrain/graphql/templates/mutation.erb +24 -26
  55. data/lib/generators/ibrain/graphql/templates/object.erb +6 -10
  56. data/lib/generators/ibrain/graphql/templates/resolver.erb +9 -11
  57. data/lib/generators/ibrain/graphql/templates/resolvers.erb +8 -10
  58. data/lib/generators/ibrain/graphql/type_generator.rb +84 -88
  59. data/lib/generators/ibrain/install/install_generator.rb +137 -140
  60. data/lib/generators/ibrain/install/templates/graphql/types/mutation_type.rb.tt +13 -15
  61. data/lib/generators/ibrain/install/templates/graphql/types/query_type.rb.tt +11 -13
  62. data/lib/generators/ibrain/install/templates/rubocop.yml.tt +83 -30
  63. data/lib/ibrain/app_configuration.rb +34 -36
  64. data/lib/ibrain/core/class_constantizer.rb +30 -33
  65. data/lib/ibrain/core/controller_helpers/auth.rb +53 -59
  66. data/lib/ibrain/core/controller_helpers/current_host.rb +5 -11
  67. data/lib/ibrain/core/controller_helpers/response.rb +43 -49
  68. data/lib/ibrain/core/controller_helpers/strong_parameters.rb +9 -15
  69. data/lib/ibrain/core/engine.rb +5 -9
  70. data/lib/ibrain/core/environment.rb +5 -9
  71. data/lib/ibrain/core/environment_extension.rb +13 -17
  72. data/lib/ibrain/core/role_configuration.rb +52 -54
  73. data/lib/ibrain/core/validators/email.rb +15 -17
  74. data/lib/ibrain/core/version.rb +2 -2
  75. data/lib/ibrain/core/versioned_value.rb +61 -65
  76. data/lib/ibrain/encryptor.rb +18 -20
  77. data/lib/ibrain/logger.rb +13 -15
  78. data/lib/ibrain/permission_sets/base.rb +22 -26
  79. data/lib/ibrain/permission_sets/super_user.rb +3 -7
  80. data/lib/ibrain/permitted_attributes.rb +18 -20
  81. data/lib/ibrain/preferences/configuration.rb +135 -137
  82. data/lib/ibrain/preferences/preferable.rb +158 -162
  83. data/lib/ibrain/preferences/preferable_class_methods.rb +112 -114
  84. data/lib/ibrain/user_class_handle.rb +22 -24
  85. metadata +2 -2
@@ -6,7 +6,12 @@ require:
6
6
  - rubocop-graphql
7
7
 
8
8
  AllCops:
9
- TargetRubyVersion: 2.5
9
+ Exclude:
10
+ - db/migrate/*.rb
11
+ - bin/*
12
+ - config/application.rb
13
+ - "**/vendor/**/*"
14
+ - vendor/eco-api-ruby
10
15
 
11
16
  # We use class vars and will have to continue doing so for compatability
12
17
  Style/ClassVars:
@@ -27,9 +32,6 @@ Naming/AccessorMethodName:
27
32
  Style/MutableConstant:
28
33
  Enabled: false
29
34
 
30
- Style/ClassAndModuleChildren:
31
- Enabled: false
32
-
33
35
  Style/EmptyElse:
34
36
  Enabled: false
35
37
 
@@ -49,7 +51,7 @@ Style/ConditionalAssignment:
49
51
  Enabled: false
50
52
 
51
53
  Performance/Count:
52
- Enabled: false
54
+ Enabled: true
53
55
 
54
56
  Style/RaiseArgs:
55
57
  Enabled: false
@@ -66,44 +68,44 @@ Style/AsciiComments:
66
68
  Enabled: false
67
69
 
68
70
  Layout/EndAlignment:
69
- Enabled: false
71
+ Enabled: true
70
72
 
71
73
  Layout/ElseAlignment:
72
- Enabled: false
74
+ Enabled: true
73
75
 
74
76
  Layout/IndentationWidth:
75
- Enabled: false
77
+ Enabled: true
76
78
 
77
79
  Layout/ParameterAlignment:
78
- Enabled: false
80
+ Enabled: true
79
81
 
80
82
  Layout/ClosingParenthesisIndentation:
81
- Enabled: false
83
+ Enabled: true
82
84
 
83
85
  Layout/MultilineMethodCallIndentation:
84
- Enabled: false
86
+ Enabled: true
85
87
 
86
88
  Layout/FirstArrayElementIndentation:
87
- Enabled: false
89
+ Enabled: true
88
90
 
89
91
  Layout/FirstHashElementIndentation:
90
- Enabled: false
92
+ Enabled: true
91
93
 
92
94
  Layout/HashAlignment:
93
- Enabled: false
95
+ Enabled: true
94
96
 
95
97
  Style/TrailingCommaInArguments:
96
- Enabled: false
98
+ Enabled: true
97
99
 
98
100
  Style/TrailingCommaInArrayLiteral:
99
- Enabled: false
101
+ Enabled: true
100
102
 
101
103
  Style/TrailingCommaInHashLiteral:
102
- Enabled: false
104
+ Enabled: true
103
105
 
104
106
  # Symbol Arrays are ok and the %i syntax widely unknown
105
107
  Style/SymbolArray:
106
- Enabled: false
108
+ Enabled: true
107
109
 
108
110
  Rails/DynamicFindBy:
109
111
  Whitelist:
@@ -114,7 +116,7 @@ Rails/DynamicFindBy:
114
116
  Rails/SkipsModelValidations:
115
117
  Exclude:
116
118
  - db/seeds/**/*.rb
117
- - '*/spec/**/*'
119
+ - "*/spec/**/*"
118
120
 
119
121
  # We use a lot of
120
122
  #
@@ -125,13 +127,13 @@ Rails/SkipsModelValidations:
125
127
  # syntax in the specs files.
126
128
  Lint/AmbiguousBlockAssociation:
127
129
  Exclude:
128
- - '*/spec/**/*'
129
- - 'spec/**/*' # For the benefit of apps that inherit from this config
130
+ - "*/spec/**/*"
131
+ - "spec/**/*" # For the benefit of apps that inherit from this config
130
132
 
131
133
  Security/Eval:
132
134
  Exclude:
133
- - 'Gemfile'
134
- - '*/Gemfile'
135
+ - "Gemfile"
136
+ - "*/Gemfile"
135
137
 
136
138
  Naming/VariableNumber:
137
139
  Enabled: false
@@ -235,7 +237,7 @@ Layout/SpaceInsideParens:
235
237
  StyleGuide: http://relaxed.ruby.style/#stylespaceinsideparens
236
238
 
237
239
  Style/SpecialGlobalVars:
238
- Enabled: false
240
+ Enabled: true
239
241
  StyleGuide: http://relaxed.ruby.style/#stylespecialglobalvars
240
242
 
241
243
  Style/StringLiterals:
@@ -300,6 +302,9 @@ Style/FrozenStringLiteralComment:
300
302
  Enabled: true
301
303
  EnforcedStyle: always
302
304
 
305
+ Style/FetchEnvVar:
306
+ Enabled: true
307
+
303
308
  # json.() is idiomatic in jbuilder files
304
309
  Style/LambdaCall:
305
310
  Enabled: false
@@ -315,7 +320,7 @@ Style/IdenticalConditionalBranches:
315
320
  Enabled: false
316
321
 
317
322
  Naming/MemoizedInstanceVariableName:
318
- Enabled: false
323
+ Enabled: true
319
324
 
320
325
  Lint/BinaryOperatorWithIdenticalOperands:
321
326
  Enabled: false
@@ -599,10 +604,7 @@ GraphQL/FieldDescription:
599
604
  Enabled: false
600
605
 
601
606
  GraphQL/ObjectDescription:
602
- Enabled: true
603
- Exclude:
604
- - app/graphql/policies/*.rb
605
- - app/graphql/*.rb
607
+ Enabled: false
606
608
 
607
609
  GraphQL/ExtractType:
608
610
  Enabled: false
@@ -612,4 +614,55 @@ Rails/UnknownEnv:
612
614
  - production
613
615
  - development
614
616
  - test
615
- - staging
617
+ - staging
618
+
619
+ Style/MixinUsage:
620
+ Enabled: true
621
+ Exclude:
622
+ - db/seeds/*.rb
623
+
624
+ GraphQL/ExtractInputType:
625
+ Enabled: false
626
+ GraphQL/ArgumentDescription:
627
+ Enabled: false
628
+
629
+ Style/AccessorGrouping:
630
+ Enabled: true
631
+
632
+ Layout/AccessModifierIndentation:
633
+ Enabled: true
634
+ EnforcedStyle: indent
635
+
636
+ Layout/ArrayAlignment:
637
+ Enabled: true
638
+
639
+ Layout/ArgumentAlignment:
640
+ Enabled: true
641
+
642
+ Layout/ClassStructure:
643
+ Categories:
644
+ association:
645
+ - has_many
646
+ - has_one
647
+ attribute_macros:
648
+ - attr_accessor
649
+ - attr_reader
650
+ - attr_writer
651
+ macros:
652
+ - validates
653
+ - validate
654
+ module_inclusion:
655
+ - include
656
+ - prepend
657
+ - extend
658
+ Layout/IndentationConsistency:
659
+ EnforcedStyle: indented_internal_methods
660
+
661
+ Layout/InitialIndentation:
662
+ Enabled: true
663
+
664
+ Layout/IndentationStyle:
665
+ EnforcedStyle: spaces
666
+
667
+ Style/ClassAndModuleChildren:
668
+ EnforcedStyle: compact
@@ -20,56 +20,54 @@
20
20
  require 'ibrain/preferences/configuration'
21
21
  require 'ibrain/core/environment'
22
22
 
23
- module Ibrain
24
- class AppConfiguration < Preferences::Configuration
25
- # Preferences (alphabetized to more easily lookup particular preferences)
23
+ class Ibrain::AppConfiguration < Ibrain::Preferences::Configuration
24
+ # Preferences (alphabetized to more easily lookup particular preferences)
26
25
 
27
- # @!attribute [rw] guest_token_cookie_options
28
- # @return [Hash] Add additional guest_token cookie options here (ie. domain or path)
29
- preference :guest_token_cookie_options, :hash, default: {}
26
+ # @!attribute [rw] guest_token_cookie_options
27
+ # @return [Hash] Add additional guest_token cookie options here (ie. domain or path)
28
+ preference :guest_token_cookie_options, :hash, default: {}
30
29
 
31
- # @!attribute [rw] generate_api_key_for_all_roles
32
- # @return [Boolean] Allow generating api key automatically for user
33
- # at role_user creation for all roles. (default: +false+)
34
- preference :generate_api_key_for_all_roles, :boolean, default: false
30
+ # @!attribute [rw] generate_api_key_for_all_roles
31
+ # @return [Boolean] Allow generating api key automatically for user
32
+ # at role_user creation for all roles. (default: +false+)
33
+ preference :generate_api_key_for_all_roles, :boolean, default: false
35
34
 
36
- # @!attribute [rw] mails_from
37
- # @return [String] Email address used as +From:+ field in transactional emails.
38
- preference :mails_from, :string, default: 'ibrain@example.com'
35
+ # @!attribute [rw] mails_from
36
+ # @return [String] Email address used as +From:+ field in transactional emails.
37
+ preference :mails_from, :string, default: 'ibrain@example.com'
39
38
 
40
- preference :graphql_policy, :string, default: 'Ibrain::Policies::GraphqlPolicy'
39
+ preference :graphql_policy, :string, default: 'Ibrain::Policies::GraphqlPolicy'
41
40
 
42
- # Api version for route config
43
- preference :api_version, :string, default: 'v1'
41
+ # Api version for route config
42
+ preference :api_version, :string, default: 'v1'
44
43
 
45
- # Graphql Schema name
46
- preference :graphql_schema, :string, default: 'Ibrain::BaseSchema'
44
+ # Graphql Schema name
45
+ preference :graphql_schema, :string, default: 'Ibrain::BaseSchema'
47
46
 
48
- # Graphql Encryptor key
49
- preference :ibrain_encryptor_key, :string, default: nil
47
+ # Graphql Encryptor key
48
+ preference :ibrain_encryptor_key, :string, default: nil
50
49
 
51
- # Parent controller
52
- preference :parent_controller, :string, default: 'ActionController::API'
50
+ # Parent controller
51
+ preference :parent_controller, :string, default: 'ActionController::API'
53
52
 
54
- preference :master_database, :string, default: 'primary'
53
+ preference :master_database, :string, default: 'primary'
55
54
 
56
- preference :graphql_max_depth, :integer, default: 3
55
+ preference :graphql_max_depth, :integer, default: 3
57
56
 
58
- preference :is_auto_append_mutation, :boolean, default: true
57
+ preference :is_auto_append_mutation, :boolean, default: true
59
58
 
60
- def static_model_preferences
61
- @static_model_preferences ||= Ibrain::Preferences::StaticModelPreferences.new
62
- end
59
+ def static_model_preferences
60
+ @static_model_preferences ||= Ibrain::Preferences::StaticModelPreferences.new
61
+ end
63
62
 
64
- def roles
65
- @roles ||= Ibrain::RoleConfiguration.new.tap do |roles|
66
- roles.assign_permissions :default, ['Ibrain::PermissionSets::DefaultCustomer']
67
- roles.assign_permissions :admin, ['Ibrain::PermissionSets::SuperUser']
68
- end
63
+ def roles
64
+ @roles ||= Ibrain::RoleConfiguration.new.tap do |roles|
65
+ roles.assign_permissions :default, ['Ibrain::PermissionSets::DefaultCustomer']
66
+ roles.assign_permissions :admin, ['Ibrain::PermissionSets::SuperUser']
69
67
  end
68
+ end
70
69
 
71
- def environment
72
- @environment ||= Ibrain::Core::Environment.new(self)
73
- end
70
+ def environment
71
+ @environment ||= Ibrain::Core::Environment.new(self)
74
72
  end
75
73
  end
@@ -2,40 +2,37 @@
2
2
 
3
3
  require 'active_support/core_ext/module'
4
4
 
5
- module Ibrain
6
- module Core
7
- module ClassConstantizer
8
- class Set
9
- include Enumerable
10
-
11
- def initialize
12
- @collection = ::Set.new
13
- end
14
-
15
- def <<(klass)
16
- @collection << klass.to_s
17
- end
18
-
19
- def concat(klasses)
20
- klasses.each do |klass|
21
- self << klass
22
- end
23
-
24
- self
25
- end
26
-
27
- delegate :clear, :empty?, to: :@collection
28
-
29
- def delete(object)
30
- @collection.delete(object.to_s)
31
- end
32
-
33
- def each
34
- @collection.each do |klass|
35
- yield klass.constantize
36
- end
37
- end
5
+ module Ibrain::Core::ClassConstantizer
6
+ class Set
7
+ include Enumerable
8
+
9
+ def initialize
10
+ @collection = ::Set.new
11
+ end
12
+
13
+ def <<(klass)
14
+ @collection << klass.to_s
15
+ end
16
+
17
+ def concat(klasses)
18
+ klasses.each do |klass|
19
+ self << klass
20
+ end
21
+
22
+ self
23
+ end
24
+
25
+ delegate :clear, :empty?, to: :@collection
26
+
27
+ def delete(object)
28
+ @collection.delete(object.to_s)
29
+ end
30
+
31
+ def each
32
+ @collection.each do |klass|
33
+ yield klass.constantize
38
34
  end
39
35
  end
40
36
  end
41
37
  end
38
+
@@ -1,68 +1,62 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Ibrain
4
- module Core
5
- module ControllerHelpers
6
- module Auth
7
- extend ActiveSupport::Concern
8
- include Response
9
-
10
- # @!attribute [rw] fallback_on_unauthorized
11
- # @!scope class
12
- # Extension point for overriding behaviour of access denied errors.
13
- # Default behaviour is to redirect back or to "/unauthorized" with a flash
14
- # message.
15
- # @return [Proc] action to take when access denied error is raised.
16
-
17
- included do
18
- before_action :set_guest_token
19
- helper_method :try_ibrain_current_user
20
-
21
- class_attribute :fallback_on_unauthorized
22
- self.fallback_on_unauthorized = -> do
23
- error = ::Struct.new(
24
- message: I18n.t('ibrain.authorization_failure')
25
- )
26
-
27
- render_json_error(error, :unauthorized)
28
- end
29
-
30
- rescue_from CanCan::AccessDenied do
31
- instance_exec(&fallback_on_unauthorized)
32
- end
33
- end
3
+ module Ibrain::Core::ControllerHelpers::Auth
4
+ extend ActiveSupport::Concern
5
+ include Response
6
+
7
+ # @!attribute [rw] fallback_on_unauthorized
8
+ # @!scope class
9
+ # Extension point for overriding behaviour of access denied errors.
10
+ # Default behaviour is to redirect back or to "/unauthorized" with a flash
11
+ # message.
12
+ # @return [Proc] action to take when access denied error is raised.
13
+
14
+ included do
15
+ before_action :set_guest_token
16
+ helper_method :try_ibrain_current_user
17
+
18
+ class_attribute :fallback_on_unauthorized
19
+ self.fallback_on_unauthorized = -> do
20
+ error = ::Struct.new(
21
+ message: I18n.t('ibrain.authorization_failure')
22
+ )
23
+
24
+ render_json_error(error, :unauthorized)
25
+ end
34
26
 
35
- # Needs to be overriden so that we use Brain's Ability rather than anyone else's.
36
- def current_ability
37
- @current_ability ||= Ibrain::Ability.new(try_ibrain_current_user)
38
- end
27
+ rescue_from CanCan::AccessDenied do
28
+ instance_exec(&fallback_on_unauthorized)
29
+ end
30
+ end
39
31
 
40
- def set_guest_token
41
- # if cookies.signed[:guest_token].blank?
42
- # cookies.permanent.signed[:guest_token] = Ibrain::Config[:guest_token_cookie_options].merge(
43
- # value: SecureRandom.urlsafe_base64(nil, false),
44
- # httponly: true
45
- # )
46
- # end
47
- end
32
+ # Needs to be overriden so that we use Brain's Ability rather than anyone else's.
33
+ def current_ability
34
+ @current_ability ||= Ibrain::Ability.new(try_ibrain_current_user)
35
+ end
48
36
 
49
- # proxy method to *possible* ibrain_current_user method
50
- # Authentication extensions (such as ibrain-auth) are meant to provide ibrain_current_user
51
- def try_ibrain_current_user
52
- # This one will be defined by apps looking to hook into Ibrain
53
- # As per authentication_helpers.rb
54
- if respond_to?(:ibrain_current_user, true)
55
- try(:ibrain_current_user)
56
- # This one will be defined by Devise
57
- elsif respond_to?(:current_ibrain_user, true)
58
- try(:current_ibrain_user)
59
- end
60
- rescue StandardError => e
61
- Ibrain::Logger.warn e.message.to_s
37
+ def set_guest_token
38
+ # if cookies.signed[:guest_token].blank?
39
+ # cookies.permanent.signed[:guest_token] = Ibrain::Config[:guest_token_cookie_options].merge(
40
+ # value: SecureRandom.urlsafe_base64(nil, false),
41
+ # httponly: true
42
+ # )
43
+ # end
44
+ end
62
45
 
63
- nil
64
- end
65
- end
46
+ # proxy method to *possible* ibrain_current_user method
47
+ # Authentication extensions (such as ibrain-auth) are meant to provide ibrain_current_user
48
+ def try_ibrain_current_user
49
+ # This one will be defined by apps looking to hook into Ibrain
50
+ # As per authentication_helpers.rb
51
+ if respond_to?(:ibrain_current_user, true)
52
+ try(:ibrain_current_user)
53
+ # This one will be defined by Devise
54
+ elsif respond_to?(:current_ibrain_user, true)
55
+ try(:current_ibrain_user)
66
56
  end
57
+ rescue StandardError => e
58
+ Ibrain::Logger.warn e.message.to_s
59
+
60
+ nil
67
61
  end
68
62
  end
@@ -1,17 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Ibrain
4
- module Core
5
- module ControllerHelpers
6
- module CurrentHost
7
- extend ActiveSupport::Concern
3
+ module Ibrain::Core::ControllerHelpers::CurrentHost
4
+ extend ActiveSupport::Concern
8
5
 
9
- included do
10
- before_action do
11
- ActiveStorage::Current.host = request.base_url
12
- end
13
- end
14
- end
6
+ included do
7
+ before_action do
8
+ ActiveStorage::Current.host = request.base_url
15
9
  end
16
10
  end
17
11
  end
@@ -1,53 +1,47 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Ibrain
4
- module Core
5
- module ControllerHelpers
6
- module Response
7
- extend ActiveSupport::Concern
8
-
9
- included do
10
- helper_method :render_json_error
11
- helper_method :render_json_ok
12
- end
13
-
14
- protected
15
-
16
- def render_json_error(error, status)
17
- e_message = error.try(:record).try(:errors).try(:full_messages).try(:first)
18
- e_message = error.try(:message) if e_message.blank?
19
- e_message = error.try(:details) if e_message.blank?
20
-
21
- backtrace = error.try(:backtrace).try(:join, "\n")
22
-
23
- Ibrain::Logger.error e_message
24
- Ibrain::Logger.error backtrace
25
-
26
- render json: {
27
- errors: [{
28
- message: e_message,
29
- extensions: {
30
- code: status,
31
- exception: {
32
- stacktrace: [
33
- backtrace
34
- ]
35
- }
36
- }
37
- }],
38
- message: e_message,
39
- data: nil
40
- }, status: status
41
- end
42
-
43
- def render_json_ok(data, message, errors = [])
44
- render json: {
45
- errors: errors,
46
- message: message || I18n.t('ibrain.system.message.ok'),
47
- data: data.as_json
48
- }, status: :ok
49
- end
50
- end
51
- end
3
+ module Ibrain::Core::ControllerHelpers::Response
4
+ extend ActiveSupport::Concern
5
+
6
+ included do
7
+ helper_method :render_json_error
8
+ helper_method :render_json_ok
9
+ end
10
+
11
+ protected
12
+
13
+ def render_json_error(error, status)
14
+ e_message = error.try(:record).try(:errors).try(:full_messages).try(:first)
15
+ e_message = error.try(:message) if e_message.blank?
16
+ e_message = error.try(:details) if e_message.blank?
17
+
18
+ backtrace = error.try(:backtrace).try(:join, "\n")
19
+
20
+ Ibrain::Logger.error e_message
21
+ Ibrain::Logger.error backtrace
22
+
23
+ render json: {
24
+ errors: [{
25
+ message: e_message,
26
+ extensions: {
27
+ code: status,
28
+ exception: {
29
+ stacktrace: [
30
+ backtrace
31
+ ]
32
+ }
33
+ }
34
+ }],
35
+ message: e_message,
36
+ data: nil
37
+ }, status: status
38
+ end
39
+
40
+ def render_json_ok(data, message, errors = [])
41
+ render json: {
42
+ errors: errors,
43
+ message: message || I18n.t('ibrain.system.message.ok'),
44
+ data: data.as_json
45
+ }, status: :ok
52
46
  end
53
47
  end
@@ -1,21 +1,15 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Ibrain
4
- module Core
5
- module ControllerHelpers
6
- module StrongParameters
7
- def permitted_attributes
8
- Ibrain::PermittedAttributes
9
- end
3
+ module Ibrain::Core::ControllerHelpers::StrongParameters
4
+ def permitted_attributes
5
+ Ibrain::PermittedAttributes
6
+ end
10
7
 
11
- delegate(*Ibrain::PermittedAttributes::ATTRIBUTES,
12
- to: :permitted_attributes,
13
- prefix: :permitted)
8
+ delegate(*Ibrain::PermittedAttributes::ATTRIBUTES,
9
+ to: :permitted_attributes,
10
+ prefix: :permitted)
14
11
 
15
- def permitted_user_attributes
16
- permitted_attributes.user_attributes
17
- end
18
- end
19
- end
12
+ def permitted_user_attributes
13
+ permitted_attributes.user_attributes
20
14
  end
21
15
  end
@@ -2,15 +2,11 @@
2
2
 
3
3
  require 'ibrain/config'
4
4
 
5
- module Ibrain
6
- module Core
7
- class Engine < ::Rails::Engine
8
- isolate_namespace Ibrain::Core
9
- config.generators.api_only = true
5
+ class Ibrain::Core::Engine < ::Rails::Engine
6
+ isolate_namespace Ibrain::Core
7
+ config.generators.api_only = true
10
8
 
11
- initializer "ibrain.environment", before: :load_config_initializers do |app|
12
- app.config.ibrain = Ibrain::Config.environment
13
- end
14
- end
9
+ initializer "ibrain.environment", before: :load_config_initializers do |app|
10
+ app.config.ibrain = Ibrain::Config.environment
15
11
  end
16
12
  end