foobara-http-command-connector 0.0.1 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +4 -0
  3. data/src/http/request.rb +18 -3
  4. data/src/http.rb +27 -0
  5. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ef818a0d8fe30552b816b5b24e36ef59ebbd65feeed55ed8242b583be744558c
4
- data.tar.gz: af534f045fa2ca50556cfc780286c21aaa051d4e80875949d6323f6479036937
3
+ metadata.gz: f5ccda00e728fcacf8da3a8aa2c457f47b1f4b3eea9c93c2ce5446bc8114be4c
4
+ data.tar.gz: fcd50e3249e2b0c66fa7ae2a778e5553dd21ad376277122a0593ddd3c16e1d43
5
5
  SHA512:
6
- metadata.gz: aa3e373038574199acf0ec5771194b0c78f87a1a5c17ec8589205abc9bd09eca96e855841230a94f30e4625d4cfce459e4b543bc4c7d00a1d9982c9e460239a6
7
- data.tar.gz: 30a371dbdf5260dcea73a2b76e7e9c329ab700838683bb937285c664898aca5c7ebf6741242e6ff37f9922ad1fc87d17b7fcbcfcd618d8ed5d768e6a3d365aa1
6
+ metadata.gz: 54391b8b5be54090a5441753902b9a692ad1f02fbc4cd38d0aad272da57367830e20b02745e2b7682fcd3477588ddd6cef1cff3ed67e1be32c5494adfcda9b7e
7
+ data.tar.gz: 7d6f18ee723458727316adfbadd2ca1f8b2a08b3d671db99a1f522d527f5b500373ca3cb624015be2c80677710bb1f3fa95ef3def09ef3cdc4a16a24f5fa9798
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## [0.0.3] - 2024-10-30
2
+
3
+ - Support path prefixes
4
+
1
5
  ## [0.0.1] - 2024-10-26
2
6
 
3
7
  - Initial release
data/src/http/request.rb CHANGED
@@ -13,6 +13,7 @@ module Foobara
13
13
  :host,
14
14
  :port,
15
15
  :cookies,
16
+ :prefix,
16
17
  :remote_ip,
17
18
  :response_headers
18
19
 
@@ -26,7 +27,8 @@ module Foobara
26
27
  host: nil,
27
28
  port: nil,
28
29
  cookies: nil,
29
- remote_ip: nil
30
+ remote_ip: nil,
31
+ prefix: nil
30
32
  )
31
33
  self.path = path
32
34
  self.method = method
@@ -38,6 +40,7 @@ module Foobara
38
40
  self.port = port
39
41
  self.cookies = cookies
40
42
  self.remote_ip = remote_ip
43
+ self.prefix = prefix
41
44
 
42
45
  super()
43
46
  end
@@ -86,11 +89,23 @@ module Foobara
86
89
  end
87
90
 
88
91
  def argument
89
- path.split("/")[2]
92
+ prefixless_path.split("/")[2]
90
93
  end
91
94
 
92
95
  def set_action_and_command_name
93
- @action, @full_command_name = path[1..].split("/")
96
+ @action, @full_command_name = prefixless_path[1..].split("/")
97
+ end
98
+
99
+ def prefixless_path
100
+ return @prefixless_path if defined?(@prefixless_path)
101
+
102
+ prefix = self.prefix
103
+
104
+ @prefixless_path = if prefix
105
+ path.gsub(/^#{prefix}\//, "/")
106
+ else
107
+ path
108
+ end
94
109
  end
95
110
  end
96
111
  end
data/src/http.rb CHANGED
@@ -3,6 +3,33 @@ module Foobara
3
3
  class Http < CommandConnector
4
4
  include TruncatedInspect
5
5
 
6
+ attr_accessor :prefix
7
+
8
+ def initialize(prefix: nil, **)
9
+ if prefix
10
+ if prefix.is_a?(::Array)
11
+ prefix = prefix.join("/")
12
+ end
13
+
14
+ if prefix.end_with?("/")
15
+ prefix = prefix[0..-2]
16
+ end
17
+
18
+ unless prefix.start_with?("/")
19
+ prefix = "/#{prefix}"
20
+ end
21
+
22
+ self.prefix = prefix
23
+
24
+ end
25
+
26
+ super(**)
27
+ end
28
+
29
+ def run(*, **)
30
+ super(*, prefix:, **)
31
+ end
32
+
6
33
  def request_to_command(context)
7
34
  if context.method == "OPTIONS"
8
35
  # TODO: this feels a bit hacky and like overkill...
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foobara-http-command-connector
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Miles Georgi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-10-26 00:00:00.000000000 Z
11
+ date: 2024-10-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: foobara