rage-rb 1.6.0 → 1.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +14 -0
  3. data/Gemfile +10 -7
  4. data/OVERVIEW.md +1 -1
  5. data/README.md +25 -9
  6. data/lib/rage/all.rb +1 -0
  7. data/lib/rage/cable/cable.rb +130 -0
  8. data/lib/rage/cable/channel.rb +452 -0
  9. data/lib/rage/cable/connection.rb +78 -0
  10. data/lib/rage/cable/protocol/actioncable_v1_json.rb +167 -0
  11. data/lib/rage/cable/router.rb +138 -0
  12. data/lib/rage/cli.rb +2 -1
  13. data/lib/rage/code_loader.rb +9 -0
  14. data/lib/rage/configuration.rb +53 -0
  15. data/lib/rage/controller/api.rb +51 -13
  16. data/lib/rage/cookies.rb +7 -9
  17. data/lib/rage/ext/active_record/connection_pool.rb +1 -1
  18. data/lib/rage/fiber.rb +3 -3
  19. data/lib/rage/fiber_scheduler.rb +1 -1
  20. data/lib/rage/logger/json_formatter.rb +1 -1
  21. data/lib/rage/logger/logger.rb +1 -1
  22. data/lib/rage/logger/text_formatter.rb +1 -1
  23. data/lib/rage/middleware/cors.rb +2 -2
  24. data/lib/rage/middleware/fiber_wrapper.rb +3 -1
  25. data/lib/rage/middleware/origin_validator.rb +38 -0
  26. data/lib/rage/middleware/reloader.rb +1 -1
  27. data/lib/rage/params_parser.rb +1 -1
  28. data/lib/rage/router/backend.rb +4 -6
  29. data/lib/rage/router/constrainer.rb +1 -1
  30. data/lib/rage/router/dsl.rb +7 -7
  31. data/lib/rage/router/dsl_plugins/legacy_hash_notation.rb +1 -1
  32. data/lib/rage/router/dsl_plugins/legacy_root_notation.rb +1 -1
  33. data/lib/rage/router/handler_storage.rb +1 -1
  34. data/lib/rage/session.rb +2 -2
  35. data/lib/rage/setup.rb +5 -1
  36. data/lib/rage/sidekiq_session.rb +1 -1
  37. data/lib/rage/version.rb +1 -1
  38. data/lib/rage-rb.rb +23 -15
  39. data/rage.gemspec +1 -1
  40. metadata +8 -2
@@ -17,7 +17,7 @@ class Rage::Router::DSL
17
17
  end
18
18
 
19
19
  ##
20
- # This class implements routing logic for your application, providing API similar to Rails.
20
+ # This class implements routing logic for your application, providing an API similar to Rails.
21
21
  #
22
22
  # Compared to the Rails router, the most notable difference is that a wildcard segment can only be in the last section of the path and cannot be named.
23
23
  # Example:
@@ -213,7 +213,7 @@ class Rage::Router::DSL
213
213
  @path_prefixes << path_prefix
214
214
  @module_prefixes << module_prefix
215
215
 
216
- instance_eval &block
216
+ instance_eval(&block)
217
217
 
218
218
  @path_prefixes.pop
219
219
  @module_prefixes.pop
@@ -253,7 +253,7 @@ class Rage::Router::DSL
253
253
  @module_prefixes << opts[:module] if opts[:module]
254
254
  @controllers << opts[:controller] if opts[:controller]
255
255
 
256
- instance_eval &block
256
+ instance_eval(&block)
257
257
 
258
258
  @path_prefixes.pop if opts[:path]
259
259
  @module_prefixes.pop if opts[:module]
@@ -269,7 +269,7 @@ class Rage::Router::DSL
269
269
  # end
270
270
  def defaults(defaults, &block)
271
271
  @defaults << defaults
272
- instance_eval &block
272
+ instance_eval(&block)
273
273
  @defaults.pop
274
274
  end
275
275
 
@@ -282,7 +282,7 @@ class Rage::Router::DSL
282
282
  # end
283
283
  def controller(controller, &block)
284
284
  @controllers << controller
285
- instance_eval &block
285
+ instance_eval(&block)
286
286
  @controllers.pop
287
287
  end
288
288
 
@@ -297,7 +297,7 @@ class Rage::Router::DSL
297
297
  def collection(&block)
298
298
  orig_path_prefixes = @path_prefixes
299
299
  @path_prefixes = @path_prefixes[0...-1] if @path_prefixes.last&.start_with?(":")
300
- instance_eval &block
300
+ instance_eval(&block)
301
301
  @path_prefixes = orig_path_prefixes
302
302
  end
303
303
 
@@ -317,7 +317,7 @@ class Rage::Router::DSL
317
317
  @path_prefixes = [*@path_prefixes[0...-1], ":#{member_prefix}"]
318
318
  end
319
319
 
320
- instance_eval &block
320
+ instance_eval(&block)
321
321
 
322
322
  @path_prefixes = orig_path_prefixes
323
323
  end
@@ -40,7 +40,7 @@ module Rage::Router::DSLPlugins::LegacyHashNotation
40
40
  options = kwargs.except(app).merge(at: at)
41
41
  super(app, **options)
42
42
  else
43
- super(*args, **kwargs)
43
+ super
44
44
  end
45
45
  end
46
46
  end
@@ -8,7 +8,7 @@ module Rage::Router::DSLPlugins::LegacyRootNotation
8
8
  if args.length == 1 && args[0].is_a?(String) && kwargs.empty?
9
9
  super(to: args[0])
10
10
  else
11
- super(*args, **kwargs)
11
+ super
12
12
  end
13
13
  end
14
14
  end
@@ -64,7 +64,7 @@ class Rage::Router::HandlerStorage
64
64
  end
65
65
  end
66
66
 
67
- eval "->(param_values) { { #{lines.join(',')} } }"
67
+ eval "->(param_values) { { #{lines.join(",")} } }"
68
68
  end
69
69
 
70
70
  def get_handler_matching_constraints(_derived_constraints)
data/lib/rage/session.rb CHANGED
@@ -7,8 +7,8 @@ class Rage::Session
7
7
  KEY = Rack::RACK_SESSION.to_sym
8
8
 
9
9
  # @private
10
- def initialize(controller)
11
- @cookies = controller.cookies.encrypted
10
+ def initialize(cookies)
11
+ @cookies = cookies.encrypted
12
12
  end
13
13
 
14
14
  # Writes the value to the session.
data/lib/rage/setup.rb CHANGED
@@ -1,6 +1,10 @@
1
1
  Iodine.patch_rack
2
2
 
3
- require_relative "#{Rage.root}/config/environments/#{Rage.env}"
3
+ begin
4
+ require_relative "#{Rage.root}/config/environments/#{Rage.env}"
5
+ rescue LoadError
6
+ raise LoadError, "The <#{Rage.env}> environment could not be found. Please check the environment name."
7
+ end
4
8
 
5
9
  # Run application initializers
6
10
  Dir["#{Rage.root}/config/initializers/**/*.rb"].each { |initializer| load(initializer) }
@@ -13,7 +13,7 @@ class Rage::SidekiqSession
13
13
  SESSION_KEY = "rage.sidekiq.session"
14
14
 
15
15
  def self.with_session(env)
16
- env["rack.session"] = session = self.new(env)
16
+ env["rack.session"] = session = new(env)
17
17
  response = yield
18
18
 
19
19
  if session.changed
data/lib/rage/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Rage
4
- VERSION = "1.6.0"
4
+ VERSION = "1.8.0"
5
5
  end
data/lib/rage-rb.rb CHANGED
@@ -7,27 +7,17 @@ require "pathname"
7
7
 
8
8
  module Rage
9
9
  def self.application
10
- app = Application.new(__router)
11
-
12
- config.middleware.middlewares.reverse.inject(app) do |next_in_chain, (middleware, args, block)|
13
- # in Rails compatibility mode we first check if the middleware is a part of the Rails middleware stack;
14
- # if it is - it is expected to be built using `ActionDispatch::MiddlewareStack::Middleware#build`
15
- if Rage.config.internal.rails_mode
16
- rails_middleware = Rails.application.config.middleware.middlewares.find { |m| m.name == middleware.name }
17
- end
18
-
19
- if rails_middleware
20
- rails_middleware.build(next_in_chain)
21
- else
22
- middleware.new(next_in_chain, *args, &block)
23
- end
24
- end
10
+ with_middlewares(Application.new(__router), config.middleware.middlewares)
25
11
  end
26
12
 
27
13
  def self.multi_application
28
14
  Rage::Router::Util::Cascade.new(application, Rails.application)
29
15
  end
30
16
 
17
+ def self.cable
18
+ Rage::Cable
19
+ end
20
+
31
21
  def self.routes
32
22
  Rage::Router::DSL.new(__router)
33
23
  end
@@ -90,6 +80,23 @@ module Rage
90
80
  end
91
81
  end
92
82
 
83
+ # @private
84
+ def self.with_middlewares(app, middlewares)
85
+ middlewares.reverse.inject(app) do |next_in_chain, (middleware, args, block)|
86
+ # in Rails compatibility mode we first check if the middleware is a part of the Rails middleware stack;
87
+ # if it is - it is expected to be built using `ActionDispatch::MiddlewareStack::Middleware#build`
88
+ if Rage.config.internal.rails_mode
89
+ rails_middleware = Rails.application.config.middleware.middlewares.find { |m| m.name == middleware.name }
90
+ end
91
+
92
+ if rails_middleware
93
+ rails_middleware.build(next_in_chain)
94
+ else
95
+ middleware.new(next_in_chain, *args, &block)
96
+ end
97
+ end
98
+ end
99
+
93
100
  module Router
94
101
  module Strategies
95
102
  end
@@ -106,6 +113,7 @@ module Rage
106
113
 
107
114
  autoload :Cookies, "rage/cookies"
108
115
  autoload :Session, "rage/session"
116
+ autoload :Cable, "rage/cable/cable"
109
117
  end
110
118
 
111
119
  module RageController
data/rage.gemspec CHANGED
@@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
20
20
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
21
21
  spec.files = Dir.chdir(__dir__) do
22
22
  `git ls-files -z`.split("\x0").reject do |f|
23
- (File.expand_path(f) == __FILE__) || f.start_with?(*%w[bin/ test/ spec/ features/ .git .circleci appveyor])
23
+ (File.expand_path(f) == __FILE__) || f.start_with?(*%w[bin/ test/ spec/ features/ .git .circleci appveyor .rubocop])
24
24
  end
25
25
  end
26
26
  spec.bindir = "exe"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rage-rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.0
4
+ version: 1.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Roman Samoilov
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-07-15 00:00:00.000000000 Z
11
+ date: 2024-08-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -102,6 +102,11 @@ files:
102
102
  - lib/rage.rb
103
103
  - lib/rage/all.rb
104
104
  - lib/rage/application.rb
105
+ - lib/rage/cable/cable.rb
106
+ - lib/rage/cable/channel.rb
107
+ - lib/rage/cable/connection.rb
108
+ - lib/rage/cable/protocol/actioncable_v1_json.rb
109
+ - lib/rage/cable/router.rb
105
110
  - lib/rage/cli.rb
106
111
  - lib/rage/code_loader.rb
107
112
  - lib/rage/configuration.rb
@@ -118,6 +123,7 @@ files:
118
123
  - lib/rage/logger/text_formatter.rb
119
124
  - lib/rage/middleware/cors.rb
120
125
  - lib/rage/middleware/fiber_wrapper.rb
126
+ - lib/rage/middleware/origin_validator.rb
121
127
  - lib/rage/middleware/reloader.rb
122
128
  - lib/rage/params_parser.rb
123
129
  - lib/rage/rails.rb