rage-rb 1.7.0 → 1.9.0

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.
data/lib/rage/request.rb CHANGED
@@ -37,6 +37,45 @@ class Rage::Request
37
37
  )
38
38
  end
39
39
 
40
+ # Returns the full URL of the request.
41
+ # @example
42
+ # request.url # => "https://example.com/users?show_archived=true"
43
+ def url
44
+ scheme = @env["rack.url_scheme"]
45
+ host = @env["SERVER_NAME"]
46
+ port = @env["SERVER_PORT"]
47
+ path = @env["PATH_INFO"]
48
+ query_string = @env["QUERY_STRING"]
49
+
50
+ port_part = (scheme == "http" && port == "80") || (scheme == "https" && port == "443") ? "" : ":#{port}"
51
+ query_part = query_string.empty? ? "" : "?#{query_string}"
52
+
53
+ "#{scheme}://#{host}#{port_part}#{path}#{query_part}"
54
+ end
55
+
56
+ # Returns the path of the request.
57
+ # @example
58
+ # request.path # => "/users"
59
+ def path
60
+ @env["PATH_INFO"]
61
+ end
62
+
63
+ # Returns the full path including the query string.
64
+ # @example
65
+ # request.fullpath # => "/users?show_archived=true"
66
+ def fullpath
67
+ path = @env["PATH_INFO"]
68
+ query_string = @env["QUERY_STRING"]
69
+ query_string.empty? ? path : "#{path}?#{query_string}"
70
+ end
71
+
72
+ # Returns the user agent of the request.
73
+ # @example
74
+ # request.user_agent # => "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36"
75
+ def user_agent
76
+ @env["HTTP_USER_AGENT"]
77
+ end
78
+
40
79
  private
41
80
 
42
81
  def if_none_match
@@ -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:
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/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Rage
4
- VERSION = "1.7.0"
4
+ VERSION = "1.9.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
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.7.0
4
+ version: 1.9.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-30 00:00:00.000000000 Z
11
+ date: 2024-08-24 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