ibrain-core 0.4.6 → 0.4.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (86) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/ibrain/base_controller.rb +14 -12
  3. data/app/controllers/ibrain/core/graphql_controller.rb +83 -79
  4. data/app/graphql/ibrain/base_schema.rb +52 -50
  5. data/app/graphql/ibrain/extentions/default_value.rb +11 -7
  6. data/app/graphql/ibrain/extentions/roles.rb +20 -15
  7. data/app/graphql/ibrain/extentions/session_required.rb +14 -10
  8. data/app/graphql/ibrain/lazy/base.rb +6 -2
  9. data/app/graphql/ibrain/loaders/association_loader.rb +55 -51
  10. data/app/graphql/ibrain/mutations/base_mutation.rb +56 -52
  11. data/app/graphql/ibrain/policies/base_policy.rb +47 -43
  12. data/app/graphql/ibrain/policies/graphql_policy.rb +6 -2
  13. data/app/graphql/ibrain/resolvers/base_aggregate.rb +10 -6
  14. data/app/graphql/ibrain/resolvers/base_resolver.rb +12 -8
  15. data/app/graphql/ibrain/types/aggregate_type.rb +8 -4
  16. data/app/graphql/ibrain/types/attribute_type.rb +5 -2
  17. data/app/graphql/ibrain/types/base_api_connection.rb +10 -6
  18. data/app/graphql/ibrain/types/base_api_edge.rb +8 -4
  19. data/app/graphql/ibrain/types/base_api_field.rb +11 -7
  20. data/app/graphql/ibrain/types/base_api_object.rb +10 -6
  21. data/app/graphql/ibrain/types/base_argument.rb +7 -3
  22. data/app/graphql/ibrain/types/base_connection.rb +11 -7
  23. data/app/graphql/ibrain/types/base_edge.rb +7 -3
  24. data/app/graphql/ibrain/types/base_enum.rb +5 -1
  25. data/app/graphql/ibrain/types/base_field.rb +10 -6
  26. data/app/graphql/ibrain/types/base_input_object.rb +10 -6
  27. data/app/graphql/ibrain/types/base_interface.rb +9 -5
  28. data/app/graphql/ibrain/types/base_object.rb +16 -12
  29. data/app/graphql/ibrain/types/base_scalar.rb +5 -1
  30. data/app/graphql/ibrain/types/base_type.rb +10 -4
  31. data/app/graphql/ibrain/types/base_union.rb +7 -3
  32. data/app/graphql/ibrain/types/filter_type.rb +5 -1
  33. data/app/graphql/ibrain/types/node_type.rb +8 -4
  34. data/app/graphql/ibrain/util/field_combiner.rb +9 -5
  35. data/app/graphql/ibrain/util/query_combiner.rb +8 -4
  36. data/app/models/concerns/ibrain/soft_deletable.rb +8 -6
  37. data/app/models/concerns/ibrain/user_api_authentication.rb +16 -14
  38. data/app/models/concerns/ibrain/user_methods.rb +13 -11
  39. data/app/models/ibrain/ability.rb +32 -31
  40. data/app/models/ibrain/aggregate.rb +7 -5
  41. data/app/models/ibrain/application_record.rb +4 -2
  42. data/app/models/ibrain/legacy_user.rb +13 -7
  43. data/app/models/ibrain/role.rb +8 -6
  44. data/app/models/ibrain/role_user.rb +10 -8
  45. data/app/repositories/ibrain/base_repository.rb +11 -9
  46. data/lib/generators/ibrain/core/model_generator.rb +21 -17
  47. data/lib/generators/ibrain/graphql/core.rb +59 -55
  48. data/lib/generators/ibrain/graphql/mutation_generator.rb +66 -58
  49. data/lib/generators/ibrain/graphql/object_generator.rb +70 -58
  50. data/lib/generators/ibrain/graphql/resolver_generator.rb +25 -17
  51. data/lib/generators/ibrain/graphql/resolvers_generator.rb +67 -59
  52. data/lib/generators/ibrain/graphql/templates/aggregate.erb +7 -5
  53. data/lib/generators/ibrain/graphql/templates/input.erb +9 -5
  54. data/lib/generators/ibrain/graphql/templates/mutation.erb +26 -24
  55. data/lib/generators/ibrain/graphql/templates/object.erb +10 -6
  56. data/lib/generators/ibrain/graphql/templates/resolver.erb +11 -9
  57. data/lib/generators/ibrain/graphql/templates/resolvers.erb +10 -8
  58. data/lib/generators/ibrain/graphql/type_generator.rb +88 -84
  59. data/lib/generators/ibrain/install/install_generator.rb +140 -137
  60. data/lib/generators/ibrain/install/templates/graphql/types/mutation_type.rb.tt +15 -13
  61. data/lib/generators/ibrain/install/templates/graphql/types/query_type.rb.tt +13 -11
  62. data/lib/generators/ibrain/install/templates/rubocop.yml.tt +30 -83
  63. data/lib/ibrain/app_configuration.rb +36 -34
  64. data/lib/ibrain/core/class_constantizer.rb +33 -30
  65. data/lib/ibrain/core/controller_helpers/auth.rb +59 -53
  66. data/lib/ibrain/core/controller_helpers/current_host.rb +11 -5
  67. data/lib/ibrain/core/controller_helpers/response.rb +49 -43
  68. data/lib/ibrain/core/controller_helpers/strong_parameters.rb +15 -9
  69. data/lib/ibrain/core/engine.rb +9 -5
  70. data/lib/ibrain/core/environment.rb +9 -5
  71. data/lib/ibrain/core/environment_extension.rb +17 -13
  72. data/lib/ibrain/core/role_configuration.rb +54 -52
  73. data/lib/ibrain/core/validators/email.rb +17 -15
  74. data/lib/ibrain/core/version.rb +2 -2
  75. data/lib/ibrain/core/versioned_value.rb +65 -61
  76. data/lib/ibrain/encryptor.rb +20 -18
  77. data/lib/ibrain/logger.rb +15 -13
  78. data/lib/ibrain/permission_sets/base.rb +26 -22
  79. data/lib/ibrain/permission_sets/super_user.rb +7 -3
  80. data/lib/ibrain/permitted_attributes.rb +20 -18
  81. data/lib/ibrain/preferences/configuration.rb +137 -135
  82. data/lib/ibrain/preferences/preferable.rb +162 -158
  83. data/lib/ibrain/preferences/preferable_class_methods.rb +114 -112
  84. data/lib/ibrain/user_class_handle.rb +24 -22
  85. data/lib/ibrain_core.rb +1 -7
  86. metadata +1 -1
@@ -7,106 +7,110 @@ require 'active_support'
7
7
  require 'active_support/core_ext/string/inflections'
8
8
  require_relative 'core'
9
9
 
10
- class Ibrain::Graphql::TypeGeneratorBase < Rails::Generators::Base
11
- include Core
10
+ module Ibrain
11
+ module Graphql
12
+ class TypeGeneratorBase < Rails::Generators::Base
13
+ include Core
12
14
 
13
- argument :type_name,
14
- type: :string,
15
- banner: "TypeName",
16
- desc: "Name of this object type (expressed as Ruby or GraphQL)"
15
+ argument :type_name,
16
+ type: :string,
17
+ banner: "TypeName",
18
+ desc: "Name of this object type (expressed as Ruby or GraphQL)"
17
19
 
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]
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)
47
41
  else
48
- ["Types::#{type_expression.camelize}Type", null]
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
49
59
  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}"
56
60
  end
57
- end
58
- end
59
61
 
60
- private
62
+ private
61
63
 
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
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
66
68
 
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
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
71
73
 
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
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
76
78
 
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
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
81
83
 
82
- def input_ruby_name
83
- @input_ruby_name ||= self.class.normalize_type_expression(type_name, mode: :input)[0]
84
- end
84
+ def input_ruby_name
85
+ @input_ruby_name ||= self.class.normalize_type_expression(type_name, mode: :input)[0]
86
+ end
85
87
 
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"]
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"]
89
91
 
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
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
96
98
 
97
- class NormalizedField
98
- def initialize(name, type_expr, null)
99
- @name = name
100
- @type_expr = type_expr
101
- @null = null
102
- end
99
+ class NormalizedField
100
+ def initialize(name, type_expr, null)
101
+ @name = name
102
+ @type_expr = type_expr
103
+ @null = null
104
+ end
103
105
 
104
- def to_ruby
105
- "field :#{@name}, #{@type_expr}, null: #{@null}"
106
- end
106
+ def to_ruby
107
+ "field :#{@name}, #{@type_expr}, null: #{@null}"
108
+ end
107
109
 
108
- def to_argument
109
- "argument :#{@name}, #{@type_expr}, required: #{@null}"
110
+ def to_argument
111
+ "argument :#{@name}, #{@type_expr}, required: #{@null}"
112
+ end
113
+ end
110
114
  end
111
115
  end
112
116
  end
@@ -3,175 +3,178 @@
3
3
  require 'rails/generators'
4
4
  require 'ibrain/logger'
5
5
 
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
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
30
32
 
31
- def create_overrides_directory
32
- empty_directory "app/overrides"
33
- end
33
+ def create_overrides_directory
34
+ empty_directory "app/overrides"
35
+ end
34
36
 
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
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
40
43
  end
41
- end
42
44
 
43
- def plugin_install_preparation
44
- @plugins_to_be_installed = []
45
- @plugin_generators_to_run = []
46
- end
45
+ def plugin_install_preparation
46
+ @plugins_to_be_installed = []
47
+ @plugin_generators_to_run = []
48
+ end
47
49
 
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.
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.
52
54
 
53
- Would you like to install it? (Y/n)"))
55
+ Would you like to install it? (Y/n)"))
54
56
 
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]}"
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
57
60
  end
58
- end
59
61
 
60
- def run_bundle_install_if_needed_by_plugins
61
- @plugins_to_be_installed.each do |plugin_name|
62
- gem plugin_name
63
- end
62
+ def run_bundle_install_if_needed_by_plugins
63
+ @plugins_to_be_installed.each do |plugin_name|
64
+ gem plugin_name
65
+ end
64
66
 
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
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
71
73
 
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
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
80
82
 
81
- append_gem('annotate', '3.1.1', 'development') if options[:with_annotation]
82
- append_gem('sendgrid-ruby', '6.6.0') if options[:with_sendgrid]
83
+ append_gem('annotate', '3.1.1', 'development') if options[:with_annotation]
84
+ append_gem('sendgrid-ruby', '6.6.0') if options[:with_sendgrid]
83
85
 
84
- if options[:with_ridgepole]
85
- append_gem('ridgepole', '1.0.0', 'development')
86
- else
87
- remove_gem('ridgepole')
88
- end
86
+ if options[:with_ridgepole]
87
+ append_gem('ridgepole', '1.0.0', 'development')
88
+ else
89
+ remove_gem('ridgepole')
90
+ end
89
91
 
90
- bundle_cleanly{ run "bundle install" } if @plugins_to_be_installed.any?
91
- run "spring stop" if defined?(Spring)
92
+ bundle_cleanly{ run "bundle install" } if @plugins_to_be_installed.any?
93
+ run "spring stop" if defined?(Spring)
92
94
 
93
- @plugin_generators_to_run.each do |plugin_generator_name|
94
- generate plugin_generator_name.to_s
95
+ @plugin_generators_to_run.each do |plugin_generator_name|
96
+ generate plugin_generator_name.to_s
97
+ end
95
98
  end
96
- end
97
99
 
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
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
113
116
  end
114
- end
115
117
 
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: '/'"
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
121
124
  end
122
- end
123
125
 
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 }
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
135
138
  end
136
- end
137
139
 
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!"
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
144
147
  end
145
- end
146
148
 
147
- private
149
+ private
148
150
 
149
- def bundle_cleanly(&block)
150
- Bundler.respond_to?(:with_unbundled_env) ? Bundler.with_unbundled_env(&block) : Bundler.with_clean_env(&block)
151
- end
151
+ def bundle_cleanly(&block)
152
+ Bundler.respond_to?(:with_unbundled_env) ? Bundler.with_unbundled_env(&block) : Bundler.with_clean_env(&block)
153
+ end
152
154
 
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(' ')
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(' ')
158
160
 
159
- system( `echo "#{string_command}" >> Gemfile` ) unless gems.include?("#{name}-")
160
- end
161
+ system( `echo "#{string_command}" >> Gemfile` ) unless gems.include?("#{name}-")
162
+ end
161
163
 
162
- def remove_gem(name)
163
- gems = Gem.loaded_specs.values.map(&:full_name).join(' ')
164
+ def remove_gem(name)
165
+ gems = Gem.loaded_specs.values.map(&:full_name).join(' ')
164
166
 
165
- system( "bundle remove #{name}" ) if gems.include?("#{name}-")
166
- end
167
+ system( "bundle remove #{name}" ) if gems.include?("#{name}-")
168
+ end
167
169
 
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))
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))
172
174
 
173
- create_file destination, nil, config do
174
- File.read(source)
175
+ create_file destination, nil, config do
176
+ File.read(source)
177
+ end
175
178
  end
176
179
  end
177
180
  end
@@ -1,20 +1,22 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- class Types::MutationType < Ibrain::Types::BaseApiObject
4
- description 'Define all mutation for client'
3
+ module Types
4
+ class MutationType < Ibrain::Types::BaseApiObject
5
+ description 'Define all mutation for client'
5
6
 
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'
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'
10
11
 
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
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
16
17
 
17
- def test_authenticated_field
18
- 'Im logged in!'
18
+ def test_authenticated_field
19
+ 'Im logged in!'
20
+ end
19
21
  end
20
22
  end
@@ -1,17 +1,19 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- class Types::QueryType < Ibrain::Types::BaseApiObject
4
- description 'Define all resolver for client'
3
+ module Types
4
+ class QueryType < Ibrain::Types::BaseApiObject
5
+ description 'Define all resolver for client'
5
6
 
6
- # Add `node(id: ID!) and `nodes(ids: [ID!]!)`
7
- include GraphQL::Types::Relay::HasNodeField
8
- include GraphQL::Types::Relay::HasNodesField
7
+ # Add `node(id: ID!) and `nodes(ids: [ID!]!)`
8
+ include GraphQL::Types::Relay::HasNodeField
9
+ include GraphQL::Types::Relay::HasNodesField
9
10
 
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.
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.
13
14
 
14
- # Example with user resolvers
15
- # field :authenticated_users, resolver: Resolvers::UsersResolver
16
- # field :users, resolver: Resolvers::UsersResolver, session_required: false
15
+ # Example with user resolvers
16
+ # field :authenticated_users, resolver: Resolvers::UsersResolver
17
+ # field :users, resolver: Resolvers::UsersResolver, session_required: false
18
+ end
17
19
  end