file_sv 0.3.0 → 0.4.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.
- checksums.yaml +4 -4
- data/lib/file_sv/planned_endpoint.rb +1 -0
- data/lib/file_sv/version.rb +1 -1
- data/lib/file_sv/virtual_server.rb +15 -7
- metadata +3 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 927b65d5d25d5302828bbfce2659fe74971f76507376882abc0c99705edeab01
|
4
|
+
data.tar.gz: 7efaf184c2ad0bd078f71fc90e79ce276e781e69b65f0d9382a76aa1b8fe0473
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9a505a61756806235d8be3b94abc73b28826efe05bfa57835c896fa143b02b6b334f30618518e2a590d10442b2b34fe38a05ebee6258898d913e3c407b1c6cc3
|
7
|
+
data.tar.gz: c0f19dd5fb0922d900ea5da6d8353fc140a9c284e84c353d222d37a1fd93e0b0e79164a9b70c243e78dc1d33d7eb1d75a03bfd81c7c3a618d06cb591eec7d4c1
|
@@ -34,6 +34,7 @@ class PlannedEndpoint
|
|
34
34
|
set_default_status_code
|
35
35
|
end
|
36
36
|
|
37
|
+
# @return [String] Path to serve on which is folder path less the filename
|
37
38
|
def serving_loc_for(path)
|
38
39
|
loc = File.split(path).first # TODO: Handle if path has a % at beginning of a folder
|
39
40
|
loc.gsub("#{File::SEPARATOR}%", "#{File::SEPARATOR}:")
|
data/lib/file_sv/version.rb
CHANGED
@@ -54,8 +54,14 @@ for more details'
|
|
54
54
|
|
55
55
|
# Log endpoint. Return content and status code defined by endpoint
|
56
56
|
# @param [PlannedEndpoint] endpoint Planned endpoint to serve
|
57
|
-
def serve(endpoint,
|
58
|
-
@id =
|
57
|
+
def serve(endpoint, dynamic_params = [])
|
58
|
+
@id = dynamic_params[0]
|
59
|
+
if dynamic_params.length > 1
|
60
|
+
dynamic_params[1..].each_with_index do |var, index|
|
61
|
+
inst_var = "@id#{index + 2}".to_sym
|
62
|
+
self.instance_variable_set(inst_var, var)
|
63
|
+
end
|
64
|
+
end
|
59
65
|
append_content_type(endpoint)
|
60
66
|
if ENV["debug"] == "true"
|
61
67
|
message = "Using endpoint based on file #{endpoint.serving_file_name}."
|
@@ -72,13 +78,15 @@ for more details'
|
|
72
78
|
documentation "Endpoint #{endpoint_base.path}" do
|
73
79
|
response "#{endpoints.size} kinds of response"
|
74
80
|
end
|
75
|
-
|
76
|
-
|
81
|
+
# Need to make extra params based on number of ':'
|
82
|
+
dynamic_paths = endpoint_base.path.scan(/:\w+/)
|
83
|
+
if dynamic_paths.length > 0
|
84
|
+
send(endpoint_base.method, endpoint_base.path) do |*dynamic_paths|
|
77
85
|
response["Access-Control-Allow-Origin"] = "*"
|
78
86
|
endpoint = endpoints.sample
|
79
87
|
@params = params
|
80
|
-
log({ msg: "Response", status:
|
81
|
-
serve endpoint,
|
88
|
+
log({ msg: "Response", status: endpoint.status_code, endpoint: endpoint.serving_file_name }) if request.fullpath != "/"
|
89
|
+
serve endpoint, dynamic_paths
|
82
90
|
end
|
83
91
|
else
|
84
92
|
send(endpoint_base.method, endpoint_base.path) do
|
@@ -86,7 +94,7 @@ for more details'
|
|
86
94
|
endpoint = endpoints.sample
|
87
95
|
@params = params
|
88
96
|
unless ENV["ignore_path"] && ("/#{ENV["ignore_path"]}" == endpoint_base.path)
|
89
|
-
log({ msg: "Response", status:
|
97
|
+
log({ msg: "Response", status: endpoint.status_code, endpoint: endpoint.serving_file_name }) if request.fullpath != "/"
|
90
98
|
end
|
91
99
|
serve endpoint
|
92
100
|
end
|
metadata
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: file_sv
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samuel Garratt
|
8
|
-
autorequire:
|
9
8
|
bindir: exe
|
10
9
|
cert_chain: []
|
11
|
-
date:
|
10
|
+
date: 2025-03-20 00:00:00.000000000 Z
|
12
11
|
dependencies:
|
13
12
|
- !ruby/object:Gem::Dependency
|
14
13
|
name: faker
|
@@ -139,7 +138,6 @@ metadata:
|
|
139
138
|
homepage_uri: https://gitlab.com/samuel-garratt/file_sv
|
140
139
|
source_code_uri: https://gitlab.com/samuel-garratt/file_sv
|
141
140
|
changelog_uri: https://gitlab.com/samuel-garratt/file_sv/CHANGELOG.md
|
142
|
-
post_install_message:
|
143
141
|
rdoc_options: []
|
144
142
|
require_paths:
|
145
143
|
- lib
|
@@ -154,8 +152,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
154
152
|
- !ruby/object:Gem::Version
|
155
153
|
version: '0'
|
156
154
|
requirements: []
|
157
|
-
rubygems_version: 3.
|
158
|
-
signing_key:
|
155
|
+
rubygems_version: 3.6.2
|
159
156
|
specification_version: 4
|
160
157
|
summary: REST service virtualisation through file structure.
|
161
158
|
test_files: []
|