ibrain-core 0.4.5 → 0.4.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.
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
@@ -7,110 +7,106 @@ require 'active_support'
7
7
  require 'active_support/core_ext/string/inflections'
8
8
  require_relative 'core'
9
9
 
10
- module Ibrain
11
- module Graphql
12
- class TypeGeneratorBase < Rails::Generators::Base
13
- include Core
10
+ class Ibrain::Graphql::TypeGeneratorBase < Rails::Generators::Base
11
+ include Core
14
12
 
15
- argument :type_name,
16
- type: :string,
17
- banner: "TypeName",
18
- desc: "Name of this object type (expressed as Ruby or GraphQL)"
13
+ argument :type_name,
14
+ type: :string,
15
+ banner: "TypeName",
16
+ desc: "Name of this object type (expressed as Ruby or GraphQL)"
19
17
 
20
- # Take a type expression in any combination of GraphQL or Ruby styles
21
- # and return it in a specified output style
22
- # TODO: nullability / list with `mode: :graphql` doesn't work
23
- # @param type_expresson [String]
24
- # @param mode [Symbol]
25
- # @param null [Boolean]
26
- # @return [(String, Boolean)] The type expression, followed by `null:` value
27
- def self.normalize_type_expression(type_expression, mode:, null: false)
28
- if type_expression.start_with?("!")
29
- normalize_type_expression(type_expression[1..-1], mode: mode, null: false)
30
- elsif type_expression.end_with?("!")
31
- normalize_type_expression(type_expression[0..-2], mode: mode, null: false)
32
- elsif type_expression.start_with?("[") && type_expression.end_with?("]")
33
- name, is_null = normalize_type_expression(type_expression[1..-2], mode: mode, null: null)
34
- ["[#{name}]", is_null]
35
- elsif type_expression.end_with?("Type")
36
- normalize_type_expression(type_expression[0..-5], mode: mode, null: null)
37
- elsif type_expression.start_with?("Types::")
38
- normalize_type_expression(type_expression[7..-1], mode: mode, null: null)
39
- elsif type_expression.start_with?("types.")
40
- normalize_type_expression(type_expression[6..-1], mode: mode, null: null)
18
+ # Take a type expression in any combination of GraphQL or Ruby styles
19
+ # and return it in a specified output style
20
+ # TODO: nullability / list with `mode: :graphql` doesn't work
21
+ # @param type_expresson [String]
22
+ # @param mode [Symbol]
23
+ # @param null [Boolean]
24
+ # @return [(String, Boolean)] The type expression, followed by `null:` value
25
+ def self.normalize_type_expression(type_expression, mode:, null: false)
26
+ if type_expression.start_with?("!")
27
+ normalize_type_expression(type_expression[1..-1], mode: mode, null: false)
28
+ elsif type_expression.end_with?("!")
29
+ normalize_type_expression(type_expression[0..-2], mode: mode, null: false)
30
+ elsif type_expression.start_with?("[") && type_expression.end_with?("]")
31
+ name, is_null = normalize_type_expression(type_expression[1..-2], mode: mode, null: null)
32
+ ["[#{name}]", is_null]
33
+ elsif type_expression.end_with?("Type")
34
+ normalize_type_expression(type_expression[0..-5], mode: mode, null: null)
35
+ elsif type_expression.start_with?("Types::")
36
+ normalize_type_expression(type_expression[7..-1], mode: mode, null: null)
37
+ elsif type_expression.start_with?("types.")
38
+ normalize_type_expression(type_expression[6..-1], mode: mode, null: null)
39
+ else
40
+ case mode
41
+ when :ruby
42
+ case type_expression
43
+ when "Int"
44
+ ["Integer", null]
45
+ when "Integer", "Float", "Boolean", "String", "ID"
46
+ [type_expression, null]
41
47
  else
42
- case mode
43
- when :ruby
44
- case type_expression
45
- when "Int"
46
- ["Integer", null]
47
- when "Integer", "Float", "Boolean", "String", "ID"
48
- [type_expression, null]
49
- else
50
- ["Types::#{type_expression.camelize}Type", null]
51
- end
52
- when :input
53
- ["Types::#{type_expression.camelize}Input", null]
54
- when :graphql
55
- [type_expression.camelize, null]
56
- else
57
- raise "Unexpected normalize mode: #{mode}"
58
- end
48
+ ["Types::#{type_expression.camelize}Type", null]
59
49
  end
50
+ when :input
51
+ ["Types::#{type_expression.camelize}Input", null]
52
+ when :graphql
53
+ [type_expression.camelize, null]
54
+ else
55
+ raise "Unexpected normalize mode: #{mode}"
60
56
  end
57
+ end
58
+ end
61
59
 
62
- private
60
+ private
63
61
 
64
- # @return [String] The user-provided type name, normalized to Ruby code
65
- def type_ruby_name
66
- @type_ruby_name ||= self.class.normalize_type_expression(type_name, mode: :ruby)[0]
67
- end
62
+ # @return [String] The user-provided type name, normalized to Ruby code
63
+ def type_ruby_name
64
+ @type_ruby_name ||= self.class.normalize_type_expression(type_name, mode: :ruby)[0]
65
+ end
68
66
 
69
- # @return [String] The user-provided type name, as a GraphQL name
70
- def type_graphql_name
71
- @type_graphql_name ||= self.class.normalize_type_expression(type_name, mode: :graphql)[0]
72
- end
67
+ # @return [String] The user-provided type name, as a GraphQL name
68
+ def type_graphql_name
69
+ @type_graphql_name ||= self.class.normalize_type_expression(type_name, mode: :graphql)[0]
70
+ end
73
71
 
74
- # @return [String] The user-provided type name, as a file name (without extension)
75
- def type_file_name
76
- @type_file_name ||= "#{type_graphql_name}Type".underscore
77
- end
72
+ # @return [String] The user-provided type name, as a file name (without extension)
73
+ def type_file_name
74
+ @type_file_name ||= "#{type_graphql_name}Type".underscore
75
+ end
78
76
 
79
- # @return [String] The user-provided type name, as a file name (without extension)
80
- def input_file_name
81
- @input_file_name ||= "#{type_graphql_name}Input".underscore
82
- end
77
+ # @return [String] The user-provided type name, as a file name (without extension)
78
+ def input_file_name
79
+ @input_file_name ||= "#{type_graphql_name}Input".underscore
80
+ end
83
81
 
84
- def input_ruby_name
85
- @input_ruby_name ||= self.class.normalize_type_expression(type_name, mode: :input)[0]
86
- end
82
+ def input_ruby_name
83
+ @input_ruby_name ||= self.class.normalize_type_expression(type_name, mode: :input)[0]
84
+ end
87
85
 
88
- # @return [Array<NormalizedField>] User-provided fields, in `(name, Ruby type name)` pairs
89
- def normalized_fields
90
- skip_fields = ["created_at:!Datetime", "updated_at:!Datetime"]
86
+ # @return [Array<NormalizedField>] User-provided fields, in `(name, Ruby type name)` pairs
87
+ def normalized_fields
88
+ skip_fields = ["created_at:!Datetime", "updated_at:!Datetime"]
91
89
 
92
- @normalized_fields ||= fields.reject { |f| skip_fields.include?(f) }.map { |f|
93
- name, raw_type = f.split(":", 2)
94
- type_expr, null = self.class.normalize_type_expression(raw_type, mode: :ruby)
95
- NormalizedField.new(name, type_expr, null)
96
- }
97
- end
90
+ @normalized_fields ||= fields.reject { |f| skip_fields.include?(f) }.map { |f|
91
+ name, raw_type = f.split(":", 2)
92
+ type_expr, null = self.class.normalize_type_expression(raw_type, mode: :ruby)
93
+ NormalizedField.new(name, type_expr, null)
94
+ }
95
+ end
98
96
 
99
- class NormalizedField
100
- def initialize(name, type_expr, null)
101
- @name = name
102
- @type_expr = type_expr
103
- @null = null
104
- end
97
+ class NormalizedField
98
+ def initialize(name, type_expr, null)
99
+ @name = name
100
+ @type_expr = type_expr
101
+ @null = null
102
+ end
105
103
 
106
- def to_ruby
107
- "field :#{@name}, #{@type_expr}, null: #{@null}"
108
- end
104
+ def to_ruby
105
+ "field :#{@name}, #{@type_expr}, null: #{@null}"
106
+ end
109
107
 
110
- def to_argument
111
- "argument :#{@name}, #{@type_expr}, required: #{@null}"
112
- end
113
- end
108
+ def to_argument
109
+ "argument :#{@name}, #{@type_expr}, required: #{@null}"
114
110
  end
115
111
  end
116
112
  end
@@ -3,178 +3,175 @@
3
3
  require 'rails/generators'
4
4
  require 'ibrain/logger'
5
5
 
6
- module Ibrain
7
- # @private
8
- class InstallGenerator < Rails::Generators::Base
9
- CORE_MOUNT_ROUTE = "mount Ibrain::Core::Engine"
10
- source_root File.expand_path('templates', __dir__)
11
-
12
- class_option :user_class, type: :string
13
- class_option :with_authentication, type: :boolean, default: true
14
- class_option :with_rubocop, type: :boolean, default: true
15
- class_option :with_graphql, type: :boolean, default: false
16
- class_option :with_annotation, type: :boolean, default: true
17
- class_option :with_sendgrid, type: :boolean, default: false
18
- class_option :enforce_available_locales, type: :boolean, default: nil
19
- class_option :with_ridgepole, type: :boolean, default: true
20
-
21
- def additional_tweaks
22
- return unless File.exist? 'public/robots.txt'
23
-
24
- append_file "public/robots.txt", <<-ROBOTS.strip_heredoc
25
- User-agent: *
26
- Disallow: /user
27
- Disallow: /account
28
- Disallow: /api
29
- Disallow: /password
30
- ROBOTS
31
- end
6
+ class Ibrain::InstallGenerator < Rails::Generators::Base
7
+ CORE_MOUNT_ROUTE = "mount Ibrain::Core::Engine"
8
+ source_root File.expand_path('templates', __dir__)
9
+
10
+ class_option :user_class, type: :string
11
+ class_option :with_authentication, type: :boolean, default: true
12
+ class_option :with_rubocop, type: :boolean, default: true
13
+ class_option :with_graphql, type: :boolean, default: false
14
+ class_option :with_annotation, type: :boolean, default: true
15
+ class_option :with_sendgrid, type: :boolean, default: false
16
+ class_option :enforce_available_locales, type: :boolean, default: nil
17
+ class_option :with_ridgepole, type: :boolean, default: true
18
+
19
+ def additional_tweaks
20
+ return unless File.exist? 'public/robots.txt'
21
+
22
+ append_file "public/robots.txt", <<-ROBOTS.strip_heredoc
23
+ User-agent: *
24
+ Disallow: /user
25
+ Disallow: /account
26
+ Disallow: /api
27
+ Disallow: /password
28
+ ROBOTS
29
+ end
32
30
 
33
- def create_overrides_directory
34
- empty_directory "app/overrides"
35
- end
31
+ def create_overrides_directory
32
+ empty_directory "app/overrides"
33
+ end
36
34
 
37
- def configure_application
38
- if !options[:enforce_available_locales].nil?
39
- application <<-RUBY
40
- I18n.enforce_available_locales = #{options[:enforce_available_locales]}
41
- RUBY
42
- end
35
+ def configure_application
36
+ if !options[:enforce_available_locales].nil?
37
+ application <<-RUBY
38
+ I18n.enforce_available_locales = #{options[:enforce_available_locales]}
39
+ RUBY
43
40
  end
41
+ end
44
42
 
45
- def plugin_install_preparation
46
- @plugins_to_be_installed = []
47
- @plugin_generators_to_run = []
48
- end
43
+ def plugin_install_preparation
44
+ @plugins_to_be_installed = []
45
+ @plugin_generators_to_run = []
46
+ end
49
47
 
50
- def install_auth_plugin
51
- if options[:with_authentication] && (options[:auto_accept] || !no?("
52
- Ibrain has a default authentication extension that uses Devise.
53
- You can find more info at https://github.com/john-techfox/ibrain-auth.git.
48
+ def install_auth_plugin
49
+ if options[:with_authentication] && (options[:auto_accept] || !no?("
50
+ Ibrain has a default authentication extension that uses Devise.
51
+ You can find more info at https://github.com/john-techfox/ibrain-auth.git.
54
52
 
55
- Would you like to install it? (Y/n)"))
53
+ Would you like to install it? (Y/n)"))
56
54
 
57
- @plugins_to_be_installed << 'ibrain-auth' unless system('gem list | grep ibrain-auth')
58
- @plugin_generators_to_run << "ibrain:auth:install --with-ridgpole=#{options[:with_ridgepole]}"
59
- end
55
+ @plugins_to_be_installed << 'ibrain-auth' unless system('gem list | grep ibrain-auth')
56
+ @plugin_generators_to_run << "ibrain:auth:install --with-ridgpole=#{options[:with_ridgepole]}"
60
57
  end
58
+ end
61
59
 
62
- def run_bundle_install_if_needed_by_plugins
63
- @plugins_to_be_installed.each do |plugin_name|
64
- gem plugin_name
65
- end
60
+ def run_bundle_install_if_needed_by_plugins
61
+ @plugins_to_be_installed.each do |plugin_name|
62
+ gem plugin_name
63
+ end
66
64
 
67
- if options[:with_rubocop]
68
- append_gem('rubocop', '1.23.0', 'development')
69
- append_gem('rubocop-performance', '1.12.0', 'development')
70
- append_gem('rubocop-rails', '2.12.4', 'development')
71
- append_gem('rubocop-graphql', '0.11.2', 'development')
72
- end
65
+ if options[:with_rubocop]
66
+ append_gem('rubocop', '1.23.0', 'development')
67
+ append_gem('rubocop-performance', '1.12.0', 'development')
68
+ append_gem('rubocop-rails', '2.12.4', 'development')
69
+ append_gem('rubocop-graphql', '0.11.2', 'development')
70
+ end
73
71
 
74
- if options[:with_graphql]
75
- append_gem('graphql', '1.12.6')
76
- append_gem('graphql-batch', '0.4.3')
77
- append_gem('graphql-guard', '2.0.0')
78
- append_gem('graphql-rails-generators', '1.1.2', 'development')
79
- append_gem('graphiql-rails', '1.8.0', 'development')
80
- append_gem('apollo_upload_server', '2.1')
81
- end
72
+ if options[:with_graphql]
73
+ append_gem('graphql', '1.12.6')
74
+ append_gem('graphql-batch', '0.4.3')
75
+ append_gem('graphql-guard', '2.0.0')
76
+ append_gem('graphql-rails-generators', '1.1.2', 'development')
77
+ append_gem('graphiql-rails', '1.8.0', 'development')
78
+ append_gem('apollo_upload_server', '2.1')
79
+ end
82
80
 
83
- append_gem('annotate', '3.1.1', 'development') if options[:with_annotation]
84
- append_gem('sendgrid-ruby', '6.6.0') if options[:with_sendgrid]
81
+ append_gem('annotate', '3.1.1', 'development') if options[:with_annotation]
82
+ append_gem('sendgrid-ruby', '6.6.0') if options[:with_sendgrid]
85
83
 
86
- if options[:with_ridgepole]
87
- append_gem('ridgepole', '1.0.0', 'development')
88
- else
89
- remove_gem('ridgepole')
90
- end
84
+ if options[:with_ridgepole]
85
+ append_gem('ridgepole', '1.0.0', 'development')
86
+ else
87
+ remove_gem('ridgepole')
88
+ end
91
89
 
92
- bundle_cleanly{ run "bundle install" } if @plugins_to_be_installed.any?
93
- run "spring stop" if defined?(Spring)
90
+ bundle_cleanly{ run "bundle install" } if @plugins_to_be_installed.any?
91
+ run "spring stop" if defined?(Spring)
94
92
 
95
- @plugin_generators_to_run.each do |plugin_generator_name|
96
- generate plugin_generator_name.to_s
97
- end
93
+ @plugin_generators_to_run.each do |plugin_generator_name|
94
+ generate plugin_generator_name.to_s
98
95
  end
96
+ end
99
97
 
100
- def install_routes
101
- routes_file_path = File.join('config', 'routes.rb')
102
- unless File.read(routes_file_path).include? CORE_MOUNT_ROUTE
103
- insert_into_file routes_file_path, after: "Rails.application.routes.draw do\n" do
104
- <<-RUBY
105
- # This line mounts Ibrain's routes at the root of your application.
106
- # This means, any requests to URLs such as /graphql, will go to Ibrain::GraphqlController,
107
- # any requests to URLS such as /auth, will go to Ibrain::AuthController,
108
- # If you would like to change where this engine is mounted, simply change the :at option to something different.
109
- #
110
- # We ask that you don't use the :as option here, as Ibrain relies on it being the default of "ibrain"
111
- #{CORE_MOUNT_ROUTE}, at: '/'
112
-
113
- # Please contact to Tai Nguyen Van <tainv@its-global.vn> if you have any question?
114
- RUBY
115
- end
98
+ def install_routes
99
+ routes_file_path = File.join('config', 'routes.rb')
100
+ unless File.read(routes_file_path).include? CORE_MOUNT_ROUTE
101
+ insert_into_file routes_file_path, after: "Rails.application.routes.draw do\n" do
102
+ <<-RUBY
103
+ # This line mounts Ibrain's routes at the root of your application.
104
+ # This means, any requests to URLs such as /graphql, will go to Ibrain::GraphqlController,
105
+ # any requests to URLS such as /auth, will go to Ibrain::AuthController,
106
+ # If you would like to change where this engine is mounted, simply change the :at option to something different.
107
+ #
108
+ # We ask that you don't use the :as option here, as Ibrain relies on it being the default of "ibrain"
109
+ #{CORE_MOUNT_ROUTE}, at: '/'
110
+
111
+ # Please contact to Tai Nguyen Van <tainv@its-global.vn> if you have any question?
112
+ RUBY
116
113
  end
114
+ end
117
115
 
118
- unless options[:quiet]
119
- Ibrain::Logger.info "*" * 50
120
- Ibrain::Logger.info "We added the following line to your application's config/routes.rb file:"
121
- Ibrain::Logger.info " "
122
- Ibrain::Logger.info " #{CORE_MOUNT_ROUTE}, at: '/'"
123
- end
116
+ unless options[:quiet]
117
+ Ibrain::Logger.info "*" * 50
118
+ Ibrain::Logger.info "We added the following line to your application's config/routes.rb file:"
119
+ Ibrain::Logger.info " "
120
+ Ibrain::Logger.info " #{CORE_MOUNT_ROUTE}, at: '/'"
124
121
  end
122
+ end
125
123
 
126
- def add_files
127
- template 'config/initializers/ibrain.rb.tt', 'config/initializers/ibrain.rb', { skip: true }
128
- template 'config/initializers/cors.tt', 'config/initializers/cors.rb'
129
- template 'config/puma.tt', 'config/puma.rb'
130
- yml_template 'config/database.tt', 'config/database.yml'
131
- template 'rubocop.yml.tt', '.rubocop.yml' if options[:with_rubocop]
132
-
133
- if options[:with_graphql]
134
- template 'graphql/app_schema.rb.tt', 'app/graphql/app_schema.rb', { skip: true }
135
- template 'graphql/types/mutation_type.rb.tt', 'app/graphql/types/mutation_type.rb', { skip: true }
136
- template 'graphql/types/query_type.rb.tt', 'app/graphql/types/query_type.rb', { skip: true }
137
- end
124
+ def add_files
125
+ template 'config/initializers/ibrain.rb.tt', 'config/initializers/ibrain.rb', { skip: true }
126
+ template 'config/initializers/cors.tt', 'config/initializers/cors.rb'
127
+ template 'config/puma.tt', 'config/puma.rb'
128
+ yml_template 'config/database.tt', 'config/database.yml'
129
+ template 'rubocop.yml.tt', '.rubocop.yml' if options[:with_rubocop]
130
+
131
+ if options[:with_graphql]
132
+ template 'graphql/app_schema.rb.tt', 'app/graphql/app_schema.rb', { skip: true }
133
+ template 'graphql/types/mutation_type.rb.tt', 'app/graphql/types/mutation_type.rb', { skip: true }
134
+ template 'graphql/types/query_type.rb.tt', 'app/graphql/types/query_type.rb', { skip: true }
138
135
  end
136
+ end
139
137
 
140
- def complete
141
- unless options[:quiet]
142
- Ibrain::Logger.info "*" * 50
143
- Ibrain::Logger.info "Ibrain has been installed successfully. You're all ready to go!"
144
- Ibrain::Logger.info " "
145
- Ibrain::Logger.info "Enjoy!"
146
- end
138
+ def complete
139
+ unless options[:quiet]
140
+ Ibrain::Logger.info "*" * 50
141
+ Ibrain::Logger.info "Ibrain has been installed successfully. You're all ready to go!"
142
+ Ibrain::Logger.info " "
143
+ Ibrain::Logger.info "Enjoy!"
147
144
  end
145
+ end
148
146
 
149
- private
147
+ private
150
148
 
151
- def bundle_cleanly(&block)
152
- Bundler.respond_to?(:with_unbundled_env) ? Bundler.with_unbundled_env(&block) : Bundler.with_clean_env(&block)
153
- end
149
+ def bundle_cleanly(&block)
150
+ Bundler.respond_to?(:with_unbundled_env) ? Bundler.with_unbundled_env(&block) : Bundler.with_clean_env(&block)
151
+ end
154
152
 
155
- def append_gem(name, version, group_name = nil)
156
- shell_command = ["\ngem '#{name}', '~> #{version}'"]
157
- shell_command.push("group: :#{group_name}") if group_name.present?
158
- string_command = shell_command.join(', ')
159
- gems = Gem.loaded_specs.values.map(&:full_name).join(' ')
153
+ def append_gem(name, version, group_name = nil)
154
+ shell_command = ["\ngem '#{name}', '~> #{version}'"]
155
+ shell_command.push("group: :#{group_name}") if group_name.present?
156
+ string_command = shell_command.join(', ')
157
+ gems = Gem.loaded_specs.values.map(&:full_name).join(' ')
160
158
 
161
- system( `echo "#{string_command}" >> Gemfile` ) unless gems.include?("#{name}-")
162
- end
159
+ system( `echo "#{string_command}" >> Gemfile` ) unless gems.include?("#{name}-")
160
+ end
163
161
 
164
- def remove_gem(name)
165
- gems = Gem.loaded_specs.values.map(&:full_name).join(' ')
162
+ def remove_gem(name)
163
+ gems = Gem.loaded_specs.values.map(&:full_name).join(' ')
166
164
 
167
- system( "bundle remove #{name}" ) if gems.include?("#{name}-")
168
- end
165
+ system( "bundle remove #{name}" ) if gems.include?("#{name}-")
166
+ end
169
167
 
170
- def yml_template(source, *args)
171
- config = args.last.is_a?(Hash) ? args.pop : {}
172
- destination = args.first || source.sub(/#{TEMPLATE_EXTNAME}$/o, "")
173
- source = File.expand_path(find_in_source_paths(source.to_s))
168
+ def yml_template(source, *args)
169
+ config = args.last.is_a?(Hash) ? args.pop : {}
170
+ destination = args.first || source.sub(/#{TEMPLATE_EXTNAME}$/o, "")
171
+ source = File.expand_path(find_in_source_paths(source.to_s))
174
172
 
175
- create_file destination, nil, config do
176
- File.read(source)
177
- end
173
+ create_file destination, nil, config do
174
+ File.read(source)
178
175
  end
179
176
  end
180
177
  end
@@ -1,22 +1,20 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Types
4
- class MutationType < Ibrain::Types::BaseApiObject
5
- description 'Define all mutation for client'
3
+ class Types::MutationType < Ibrain::Types::BaseApiObject
4
+ description 'Define all mutation for client'
6
5
 
7
- # TODO: remove me
8
- # Default session_required is true, set false if yout want to skip authenticated
9
- field :test_authenticated_field, , String, null: false,
10
- description: 'An example field added by the generator'
6
+ # TODO: remove me
7
+ # Default session_required is true, set false if yout want to skip authenticated
8
+ field :test_authenticated_field, , String, null: false,
9
+ description: 'An example field added by the generator'
11
10
 
12
- field :test_field, String, null: false,
13
- description: 'An example field added by the generator', session_required: false
14
- def test_field
15
- 'Hello World'
16
- end
11
+ field :test_field, String, null: false,
12
+ description: 'An example field added by the generator', session_required: false
13
+ def test_field
14
+ 'Hello World'
15
+ end
17
16
 
18
- def test_authenticated_field
19
- 'Im logged in!'
20
- end
17
+ def test_authenticated_field
18
+ 'Im logged in!'
21
19
  end
22
20
  end
@@ -1,19 +1,17 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Types
4
- class QueryType < Ibrain::Types::BaseApiObject
5
- description 'Define all resolver for client'
3
+ class Types::QueryType < Ibrain::Types::BaseApiObject
4
+ description 'Define all resolver for client'
6
5
 
7
- # Add `node(id: ID!) and `nodes(ids: [ID!]!)`
8
- include GraphQL::Types::Relay::HasNodeField
9
- include GraphQL::Types::Relay::HasNodesField
6
+ # Add `node(id: ID!) and `nodes(ids: [ID!]!)`
7
+ include GraphQL::Types::Relay::HasNodeField
8
+ include GraphQL::Types::Relay::HasNodesField
10
9
 
11
- # Add root-level fields here.
12
- # Default session_required is true, set false if yout want to skip authenticated
13
- # They will be entry points for queries on your schema.
10
+ # Add root-level fields here.
11
+ # Default session_required is true, set false if yout want to skip authenticated
12
+ # They will be entry points for queries on your schema.
14
13
 
15
- # Example with user resolvers
16
- # field :authenticated_users, resolver: Resolvers::UsersResolver
17
- # field :users, resolver: Resolvers::UsersResolver, session_required: false
18
- end
14
+ # Example with user resolvers
15
+ # field :authenticated_users, resolver: Resolvers::UsersResolver
16
+ # field :users, resolver: Resolvers::UsersResolver, session_required: false
19
17
  end