hanami 1.3.1 → 2.0.0.alpha2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (168) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +110 -6
  3. data/FEATURES.md +9 -1
  4. data/LICENSE.md +1 -1
  5. data/README.md +4 -5
  6. data/hanami.gemspec +26 -30
  7. data/lib/hanami.rb +40 -243
  8. data/lib/hanami/application.rb +338 -174
  9. data/lib/hanami/application/autoloader/inflector_adapter.rb +22 -0
  10. data/lib/hanami/application/container/boot/inflector.rb +7 -0
  11. data/lib/hanami/application/container/boot/logger.rb +8 -0
  12. data/lib/hanami/application/container/boot/rack_logger.rb +19 -0
  13. data/lib/hanami/application/container/boot/rack_monitor.rb +12 -0
  14. data/lib/hanami/application/container/boot/settings.rb +7 -0
  15. data/lib/hanami/application/router.rb +59 -0
  16. data/lib/hanami/application/routing/middleware/stack.rb +89 -0
  17. data/lib/hanami/application/routing/resolver.rb +82 -0
  18. data/lib/hanami/application/routing/resolver/node.rb +50 -0
  19. data/lib/hanami/application/routing/resolver/trie.rb +59 -0
  20. data/lib/hanami/application/settings.rb +23 -0
  21. data/lib/hanami/application/settings/definition.rb +26 -0
  22. data/lib/hanami/application/settings/loader.rb +97 -0
  23. data/lib/hanami/application/settings/struct.rb +65 -0
  24. data/lib/hanami/boot.rb +5 -0
  25. data/lib/hanami/cli/application/cli.rb +40 -0
  26. data/lib/hanami/cli/application/command.rb +47 -0
  27. data/lib/hanami/cli/application/commands.rb +16 -0
  28. data/lib/hanami/cli/application/commands/console.rb +81 -0
  29. data/lib/hanami/cli/base_command.rb +48 -0
  30. data/lib/hanami/cli/commands.rb +6 -42
  31. data/lib/hanami/cli/commands/command.rb +20 -30
  32. data/lib/hanami/cli/commands/server.rb +63 -14
  33. data/lib/hanami/configuration.rb +248 -190
  34. data/lib/hanami/configuration/middleware.rb +8 -28
  35. data/lib/hanami/configuration/router.rb +50 -0
  36. data/lib/hanami/configuration/sessions.rb +50 -0
  37. data/lib/hanami/init.rb +5 -0
  38. data/lib/hanami/server.rb +5 -69
  39. data/lib/hanami/setup.rb +8 -2
  40. data/lib/hanami/slice.rb +138 -0
  41. data/lib/hanami/version.rb +3 -1
  42. data/lib/hanami/web/rack_logger.rb +96 -0
  43. metadata +84 -228
  44. data/bin/hanami +0 -6
  45. data/lib/hanami/action/csrf_protection.rb +0 -211
  46. data/lib/hanami/action/routing_helpers.rb +0 -40
  47. data/lib/hanami/app.rb +0 -96
  48. data/lib/hanami/application_configuration.rb +0 -1495
  49. data/lib/hanami/application_name.rb +0 -108
  50. data/lib/hanami/application_namespace.rb +0 -14
  51. data/lib/hanami/assets/asset.rb +0 -72
  52. data/lib/hanami/assets/static.rb +0 -102
  53. data/lib/hanami/cli/commands/assets.rb +0 -16
  54. data/lib/hanami/cli/commands/assets/precompile.rb +0 -42
  55. data/lib/hanami/cli/commands/console.rb +0 -95
  56. data/lib/hanami/cli/commands/db.rb +0 -32
  57. data/lib/hanami/cli/commands/db/apply.rb +0 -32
  58. data/lib/hanami/cli/commands/db/console.rb +0 -44
  59. data/lib/hanami/cli/commands/db/create.rb +0 -32
  60. data/lib/hanami/cli/commands/db/drop.rb +0 -32
  61. data/lib/hanami/cli/commands/db/migrate.rb +0 -39
  62. data/lib/hanami/cli/commands/db/prepare.rb +0 -32
  63. data/lib/hanami/cli/commands/db/rollback.rb +0 -59
  64. data/lib/hanami/cli/commands/db/version.rb +0 -32
  65. data/lib/hanami/cli/commands/destroy.rb +0 -26
  66. data/lib/hanami/cli/commands/destroy/action.rb +0 -137
  67. data/lib/hanami/cli/commands/destroy/app.rb +0 -159
  68. data/lib/hanami/cli/commands/destroy/mailer.rb +0 -74
  69. data/lib/hanami/cli/commands/destroy/migration.rb +0 -51
  70. data/lib/hanami/cli/commands/destroy/model.rb +0 -84
  71. data/lib/hanami/cli/commands/generate.rb +0 -28
  72. data/lib/hanami/cli/commands/generate/action.rb +0 -321
  73. data/lib/hanami/cli/commands/generate/action/action.erb +0 -7
  74. data/lib/hanami/cli/commands/generate/action/action_spec.minitest.erb +0 -11
  75. data/lib/hanami/cli/commands/generate/action/action_spec.rspec.erb +0 -9
  76. data/lib/hanami/cli/commands/generate/action/action_without_view.erb +0 -7
  77. data/lib/hanami/cli/commands/generate/action/view.erb +0 -7
  78. data/lib/hanami/cli/commands/generate/action/view_spec.minitest.erb +0 -12
  79. data/lib/hanami/cli/commands/generate/action/view_spec.rspec.erb +0 -10
  80. data/lib/hanami/cli/commands/generate/app.rb +0 -243
  81. data/lib/hanami/cli/commands/generate/app/application.erb +0 -313
  82. data/lib/hanami/cli/commands/generate/app/favicon.ico +0 -0
  83. data/lib/hanami/cli/commands/generate/app/gitkeep.erb +0 -0
  84. data/lib/hanami/cli/commands/generate/app/layout.erb +0 -7
  85. data/lib/hanami/cli/commands/generate/app/layout_spec.minitest.erb +0 -10
  86. data/lib/hanami/cli/commands/generate/app/layout_spec.rspec.erb +0 -10
  87. data/lib/hanami/cli/commands/generate/app/routes.erb +0 -5
  88. data/lib/hanami/cli/commands/generate/app/template.erb.erb +0 -10
  89. data/lib/hanami/cli/commands/generate/app/template.haml.erb +0 -7
  90. data/lib/hanami/cli/commands/generate/app/template.slim.erb +0 -8
  91. data/lib/hanami/cli/commands/generate/mailer.rb +0 -104
  92. data/lib/hanami/cli/commands/generate/mailer/mailer.erb +0 -9
  93. data/lib/hanami/cli/commands/generate/mailer/mailer_spec.minitest.erb +0 -7
  94. data/lib/hanami/cli/commands/generate/mailer/mailer_spec.rspec.erb +0 -5
  95. data/lib/hanami/cli/commands/generate/migration.rb +0 -41
  96. data/lib/hanami/cli/commands/generate/migration/migration.erb +0 -4
  97. data/lib/hanami/cli/commands/generate/model.rb +0 -125
  98. data/lib/hanami/cli/commands/generate/model/entity.erb +0 -2
  99. data/lib/hanami/cli/commands/generate/model/entity_spec.minitest.erb +0 -5
  100. data/lib/hanami/cli/commands/generate/model/entity_spec.rspec.erb +0 -3
  101. data/lib/hanami/cli/commands/generate/model/migration.erb +0 -10
  102. data/lib/hanami/cli/commands/generate/model/repository.erb +0 -5
  103. data/lib/hanami/cli/commands/generate/model/repository_spec.minitest.erb +0 -5
  104. data/lib/hanami/cli/commands/generate/model/repository_spec.rspec.erb +0 -3
  105. data/lib/hanami/cli/commands/generate/secret.rb +0 -48
  106. data/lib/hanami/cli/commands/new.rb +0 -578
  107. data/lib/hanami/cli/commands/new/.env.development.erb +0 -3
  108. data/lib/hanami/cli/commands/new/.env.test.erb +0 -3
  109. data/lib/hanami/cli/commands/new/.gitkeep.erb +0 -0
  110. data/lib/hanami/cli/commands/new/Gemfile.erb +0 -58
  111. data/lib/hanami/cli/commands/new/README.md.erb +0 -33
  112. data/lib/hanami/cli/commands/new/config.ru.erb +0 -3
  113. data/lib/hanami/cli/commands/new/config/boot.erb +0 -2
  114. data/lib/hanami/cli/commands/new/config/environment.erb +0 -49
  115. data/lib/hanami/cli/commands/new/gitignore.erb +0 -2
  116. data/lib/hanami/cli/commands/new/gitignore_with_sqlite.erb +0 -3
  117. data/lib/hanami/cli/commands/new/hanamirc.erb +0 -3
  118. data/lib/hanami/cli/commands/new/lib/project.erb +0 -2
  119. data/lib/hanami/cli/commands/new/minitest/Rakefile.erb +0 -12
  120. data/lib/hanami/cli/commands/new/minitest/features_helper.erb +0 -11
  121. data/lib/hanami/cli/commands/new/minitest/spec_helper.erb +0 -7
  122. data/lib/hanami/cli/commands/new/rspec/Rakefile.erb +0 -9
  123. data/lib/hanami/cli/commands/new/rspec/capybara.erb +0 -8
  124. data/lib/hanami/cli/commands/new/rspec/features_helper.erb +0 -12
  125. data/lib/hanami/cli/commands/new/rspec/rspec.erb +0 -2
  126. data/lib/hanami/cli/commands/new/rspec/spec_helper.erb +0 -103
  127. data/lib/hanami/cli/commands/new/schema.sql.erb +0 -0
  128. data/lib/hanami/cli/commands/project.rb +0 -421
  129. data/lib/hanami/cli/commands/routes.rb +0 -21
  130. data/lib/hanami/cli/commands/templates.rb +0 -31
  131. data/lib/hanami/cli/commands/version.rb +0 -19
  132. data/lib/hanami/common_logger.rb +0 -93
  133. data/lib/hanami/components.rb +0 -156
  134. data/lib/hanami/components/app/assets.rb +0 -59
  135. data/lib/hanami/components/app/controller.rb +0 -74
  136. data/lib/hanami/components/app/routes.rb +0 -59
  137. data/lib/hanami/components/app/view.rb +0 -44
  138. data/lib/hanami/components/component.rb +0 -182
  139. data/lib/hanami/components/components.rb +0 -479
  140. data/lib/hanami/components/routes_inspector.rb +0 -72
  141. data/lib/hanami/config/cookies.rb +0 -69
  142. data/lib/hanami/config/framework_configuration.rb +0 -43
  143. data/lib/hanami/config/load_paths.rb +0 -46
  144. data/lib/hanami/config/mapper.rb +0 -47
  145. data/lib/hanami/config/routes.rb +0 -20
  146. data/lib/hanami/config/security.rb +0 -110
  147. data/lib/hanami/config/sessions.rb +0 -103
  148. data/lib/hanami/configuration/app.rb +0 -18
  149. data/lib/hanami/early_hints.rb +0 -129
  150. data/lib/hanami/env.rb +0 -69
  151. data/lib/hanami/environment.rb +0 -513
  152. data/lib/hanami/environment_application_configurations.rb +0 -37
  153. data/lib/hanami/frameworks.rb +0 -22
  154. data/lib/hanami/hanamirc.rb +0 -169
  155. data/lib/hanami/mailer/glue.rb +0 -27
  156. data/lib/hanami/middleware_stack.rb +0 -172
  157. data/lib/hanami/rake_helper.rb +0 -78
  158. data/lib/hanami/rake_tasks.rb +0 -2
  159. data/lib/hanami/rendering_policy.rb +0 -95
  160. data/lib/hanami/routes.rb +0 -219
  161. data/lib/hanami/routing/default.rb +0 -32
  162. data/lib/hanami/static.rb +0 -63
  163. data/lib/hanami/templates/default.html.erb +0 -30
  164. data/lib/hanami/templates/welcome.html.erb +0 -52
  165. data/lib/hanami/views/default.rb +0 -37
  166. data/lib/hanami/views/default_template_finder.rb +0 -22
  167. data/lib/hanami/views/null_view.rb +0 -15
  168. data/lib/hanami/welcome.rb +0 -36
@@ -1,72 +0,0 @@
1
- require 'hanami/routing/default'
2
- require_relative './app/routes'
3
-
4
- module Hanami
5
- # @since 0.9.0
6
- # @api private
7
- module Components
8
- # Project's routes inspector
9
- #
10
- # @since 0.9.0
11
- # @api private
12
- class RoutesInspector
13
- # @param configuration [Hanami::Configuration]
14
- #
15
- # @since 0.9.0
16
- # @api private
17
- def initialize(configuration)
18
- @configuration = configuration
19
- end
20
-
21
- # Returns a printable version of the project routes
22
- #
23
- # @return [String] printable routes
24
- #
25
- # @since 0.9.0
26
- # @api private
27
- def inspect
28
- routes.map do |r|
29
- r.inspector.to_s
30
- end.join("\n")
31
- end
32
-
33
- private
34
-
35
- # @since 0.9.0
36
- # @api private
37
- attr_reader :configuration
38
-
39
- # @since 0.9.0
40
- # @api private
41
- def routes
42
- configuration.mounted.each_with_object([]) do |(klass, app), result|
43
- result << if hanami_app?(klass)
44
- resolve_hanami_app_router(app)
45
- else
46
- resolve_rack_app_router(app)
47
- end
48
- end
49
- end
50
-
51
- # @since 0.9.0
52
- # @api private
53
- def hanami_app?(klass)
54
- klass <= Hanami::Application
55
- end
56
-
57
- # @since 0.9.0
58
- # @api private
59
- def resolve_hanami_app_router(app)
60
- App::Routes.application_routes(app)
61
- end
62
-
63
- # @since 0.9.0
64
- # @api private
65
- def resolve_rack_app_router(app)
66
- Hanami::Router.new do
67
- mount app.name, at: app.path_prefix
68
- end
69
- end
70
- end
71
- end
72
- end
@@ -1,69 +0,0 @@
1
- module Hanami
2
- # @api private
3
- module Config
4
- # Cookies configuration
5
- #
6
- # @since 0.3.0
7
- # @api private
8
- class Cookies
9
-
10
- # Return the routes for this application
11
- #
12
- # @return [Hash] options for cookies
13
- #
14
- # @since 0.3.0
15
- # @api private
16
- attr_reader :default_options
17
-
18
- # Cookies configuration
19
- #
20
- # httponly option enabled by default.
21
- # Prevent attackers to steal cookies via JavaScript,
22
- # Eg. alert(document.cookie) will fail
23
- #
24
- # @param options [Hash, TrueClass, FalseClass] optional cookies options
25
- # @param configuration [Hanami::Configuration] the application configuration
26
- #
27
- # @since 0.3.0
28
- # @api private
29
- #
30
- # @see https://github.com/rack/rack/blob/master/lib/rack/utils.rb #set_cookie_header!
31
- # @see https://www.owasp.org/index.php/HttpOnly
32
- #
33
- # @example Enable cookies with boolean
34
- # module Web
35
- # class Application < Hanami::Application
36
- # configure do
37
- # # ...
38
- # cookies true
39
- # end
40
- # end
41
- # end
42
- #
43
- # @example Enable cookies with options
44
- # module Web
45
- # class Application < Hanami::Application
46
- # configure do
47
- # # ...
48
- # cookies max_age: 300
49
- # end
50
- # end
51
- # end
52
- def initialize(configuration, options = {})
53
- @options = options
54
- @default_options = { httponly: true, secure: configuration.ssl? }
55
- @default_options.merge!(options) if options.is_a?(::Hash)
56
- end
57
-
58
- # Return if cookies are enabled
59
- #
60
- # @return [TrueClass, FalseClass] enabled cookies
61
- #
62
- # @since 0.3.0
63
- # @api private
64
- def enabled?
65
- @options.respond_to?(:empty?) ? !@options.empty? : !!@options
66
- end
67
- end
68
- end
69
- end
@@ -1,43 +0,0 @@
1
- module Hanami
2
- # @api private
3
- module Config
4
- # Collects all the settings for a given framework configuration and then
5
- # forwards them when the application is loaded.
6
- #
7
- # @since 0.2.0
8
- # @api private
9
- class FrameworkConfiguration < BasicObject
10
- # @since 0.2.0
11
- # @api private
12
- def initialize(&blk)
13
- @blocks = [blk || ::Proc.new { }]
14
- @settings = []
15
- end
16
-
17
- # @since 0.2.0
18
- # @api private
19
- def __apply(configuration)
20
- @blocks.compact.each do |blk|
21
- configuration.instance_eval(&blk)
22
- end
23
-
24
- @settings.each do |(m, args, blk)|
25
- configuration.public_send(m, *args, &blk)
26
- end
27
- end
28
-
29
- # @since 0.6.0
30
- # @api private
31
- def __add(&blk)
32
- @blocks << blk
33
- self
34
- end
35
-
36
- # @since 0.2.0
37
- # @api private
38
- def method_missing(m, *args, &blk)
39
- @settings.push([m, args, blk])
40
- end
41
- end
42
- end
43
- end
@@ -1,46 +0,0 @@
1
- require 'hanami/utils'
2
-
3
- module Hanami
4
- # @api private
5
- module Config
6
- # Define the load paths where the application should load
7
- #
8
- # @since 0.1.0
9
- # @api private
10
- class LoadPaths < Utils::LoadPaths
11
- # Overrides Utils::LoadPath initialize method
12
- #
13
- # @see Hanami::Utils::LoadPaths#initialize
14
- #
15
- # @since 0.1.0
16
- # @api private
17
- def initialize(root)
18
- super()
19
- @root = root
20
- end
21
-
22
- # Requires relative @pats [Utils::Kernel.Array] variable via each method
23
- #
24
- # @see Hanami::Utils::LoadPaths#each
25
- #
26
- # @since 0.1.0
27
- # @api private
28
- def load!
29
- each do |path|
30
- Utils.require!(path)
31
- end
32
- end
33
-
34
- protected
35
-
36
- # Overrides Utils::LoadPath realpath method
37
- #
38
- # @see Hanami::Utils::LoadPaths#realpath
39
- #
40
- # @api private
41
- def realpath(path)
42
- @root.join(path).realpath
43
- end
44
- end
45
- end
46
- end
@@ -1,47 +0,0 @@
1
- require 'hanami/utils/kernel'
2
-
3
- module Hanami
4
- # @since 0.1.0
5
- # @api private
6
- module Config
7
- # Block or file mapper
8
- #
9
- # @since 0.1.0
10
- # @api private
11
- class Mapper
12
- # @api private
13
- EXTNAME = '.rb'
14
-
15
- # @since 0.1.0
16
- # @api private
17
- def initialize(root, path, &blk)
18
- @path, @blk = path, blk
19
- @path = root.join(path) if root && path
20
- end
21
-
22
- # @since 0.1.0
23
- # @api private
24
- def to_proc
25
- return @blk if @blk
26
-
27
- code = realpath.read
28
- Proc.new { eval(code) }
29
- end
30
-
31
- private
32
- # @since 0.1.0
33
- # @api private
34
- def realpath
35
- Utils::Kernel.Pathname("#{ @path }#{ EXTNAME }").realpath
36
- rescue Errno::ENOENT
37
- raise ArgumentError, error_message
38
- end
39
-
40
- # @since 0.1.0
41
- # @api private
42
- def error_message
43
- 'You must specify a block or a file.'
44
- end
45
- end
46
- end
47
- end
@@ -1,20 +0,0 @@
1
- require 'hanami/config/mapper'
2
-
3
- module Hanami
4
- # @since 0.1.0
5
- # @api private
6
- module Config
7
- # Defines a route set
8
- #
9
- # @since 0.1.0
10
- # @api private
11
- class Routes < Mapper
12
- private
13
- # @since 0.1.0
14
- # @api private
15
- def error_message
16
- 'You must specify a block or a file for routes definitions.'
17
- end
18
- end
19
- end
20
- end
@@ -1,110 +0,0 @@
1
- module Hanami
2
- # @since 0.3.0
3
- # @api private
4
- module Config
5
- # Security policies are stored here.
6
- #
7
- # @since 0.3.0
8
- class Security
9
- # @since 0.3.0
10
- # @api private
11
- X_FRAME_OPTIONS_HEADER = 'X-Frame-Options'.freeze
12
-
13
- # @since 0.8.0
14
- # @api private
15
- X_CONTENT_TYPE_OPTIONS_HEADER = 'X-Content-Type-Options'.freeze
16
-
17
- # @since 0.8.0
18
- # @api private
19
- X_XSS_PROTECTION_HEADER = 'X-XSS-Protection'.freeze
20
-
21
- # @since 0.3.0
22
- # @api private
23
- CONTENT_SECURITY_POLICY_HEADER = 'Content-Security-Policy'.freeze
24
-
25
- # @since 0.8.0
26
- # @api private
27
- SEPARATOR = ';'.freeze
28
-
29
- # @since 0.8.0
30
- # @api private
31
- SPACED_SEPARATOR = "#{ SEPARATOR } ".freeze
32
-
33
- # X-Frame-Options headers' value
34
- #
35
- # @overload x_frame_options(value)
36
- # Sets the given value
37
- # @param value [String] for X-Frame-Options header.
38
- #
39
- # @overload x_frame_options
40
- # Gets the value
41
- # @return [String] X-Frame-Options header's value
42
- #
43
- # @since 0.3.0
44
- def x_frame_options(value = nil)
45
- if value.nil?
46
- @x_frame_options
47
- else
48
- @x_frame_options = value
49
- end
50
- end
51
-
52
- # X-Content-Type-Options headers' value
53
- #
54
- # @overload x_content_type_options(value)
55
- # Sets the given value
56
- # @param value [String] for X-Content-Type-Options header.
57
- #
58
- # @overload x_content_type_options
59
- # Gets the value
60
- # @return [String] X-Content-Type-Options header's value
61
- #
62
- # @since 0.8.0
63
- def x_content_type_options(value = nil)
64
- if value.nil?
65
- @x_content_type_options
66
- else
67
- @x_content_type_options = value
68
- end
69
- end
70
-
71
- # X-XSS-Protection headers' value
72
- #
73
- # @overload x_xss_protection(value)
74
- # Sets the given value
75
- # @param value [String] for X-XSS-Protection header.
76
- #
77
- # @overload x_xss_protection
78
- # Gets the value
79
- # @return [String] X-XSS-Protection header's value
80
- #
81
- # @since 0.8.0
82
- def x_xss_protection(value = nil)
83
- if value.nil?
84
- @x_xss_protection
85
- else
86
- @x_xss_protection = value
87
- end
88
- end
89
-
90
- # Content-Policy-Security headers' value
91
- #
92
- # @overload content_security_policy(value)
93
- # Sets the given value
94
- # @param value [String] for Content-Security-Policy header.
95
- #
96
- # @overload content_security_policy
97
- # Gets the value
98
- # @return [String] Content-Security-Policy header's value
99
- #
100
- # @since 0.3.0
101
- def content_security_policy(value = nil)
102
- if value.nil?
103
- @content_security_policy
104
- else
105
- @content_security_policy = value.split(SEPARATOR).map(&:strip).join(SPACED_SEPARATOR)
106
- end
107
- end
108
- end
109
- end
110
- end
@@ -1,103 +0,0 @@
1
- require 'ipaddr'
2
- require 'hanami/utils/string'
3
-
4
- module Hanami
5
- # @since 0.2.0
6
- # @api private
7
- module Config
8
- # Sessions configuration
9
- #
10
- # @since 0.2.0
11
- # @api private
12
- class Sessions
13
-
14
- # Ruby namespace for Rack session adapters
15
- #
16
- # @since 0.2.0
17
- # @api private
18
- RACK_NAMESPACE = 'Rack::Session::%s'.freeze
19
-
20
- # Localhost string for detecting localhost host configuration
21
- #
22
- # @since 0.2.0
23
- # @api private
24
- BLACKLISTED_DOMAINS = %w(localhost).freeze
25
-
26
- # HTTP sessions configuration
27
- #
28
- # @param adapter [Symbol,String,Class] the session adapter
29
- # @param options [Hash] the optional session options
30
- # @param configuration [Hanami::Configuration] the application configuration
31
- #
32
- # @since 0.2.0
33
- # @api private
34
- #
35
- # @see http://www.rubydoc.info/github/rack/rack/Rack/Session/Abstract/ID
36
- def initialize(adapter = nil, options = {}, configuration = nil)
37
- @adapter = adapter
38
- @options = options
39
- @configuration = configuration
40
- end
41
-
42
- # Check if the sessions are enabled
43
- #
44
- # @return [FalseClass,TrueClass] the result of the check
45
- #
46
- # @since 0.2.0
47
- # @api private
48
- def enabled?
49
- !!@adapter
50
- end
51
-
52
- # Returns the Rack middleware and the options
53
- #
54
- # @return [Array] Rack middleware and options
55
- #
56
- # @since 0.2.0
57
- # @api private
58
- def middleware
59
- middleware = case @adapter
60
- when Symbol
61
- RACK_NAMESPACE % Utils::String.classify(@adapter)
62
- else
63
- @adapter
64
- end
65
-
66
- [middleware, options]
67
- end
68
-
69
- private
70
-
71
- # @since 0.2.0
72
- # @api private
73
- def options
74
- default_options.merge(@options)
75
- end
76
-
77
- # @since 0.2.0
78
- # @api private
79
- def default_options
80
- if @configuration
81
- { domain: domain, secure: @configuration.ssl? }
82
- else
83
- {}
84
- end
85
- end
86
-
87
- # @since 0.2.0
88
- # @api private
89
- def domain
90
- domain = @configuration.host
91
- if !BLACKLISTED_DOMAINS.include?(domain) && !ip_address?(domain)
92
- domain
93
- end
94
- end
95
-
96
- # @since 0.2.0
97
- # @api private
98
- def ip_address?(string)
99
- !!IPAddr.new(string) rescue false
100
- end
101
- end
102
- end
103
- end