file_sv 0.1.10 → 0.1.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/file_sv/planned_endpoint.rb +21 -1
- data/lib/file_sv/sv_plan.rb +2 -2
- data/lib/file_sv/version.rb +1 -1
- data/lib/file_sv/virtual_server.rb +5 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f83c739611ce58614e8d076e6be444b889ff63727b174dcfbd13025e3367b2d6
|
4
|
+
data.tar.gz: 042d4b3ae8ad91e6708b19bcdf9ad5b3473682494a8a6c4879ef50e61dbcce29
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fbe538e3dad13e5bdd4af99c8d10b792397e5a1252c2a9809a5120a9aec9302a5d83aff05f3a36d9ef112a3c335184c2c97d4668fa9e44f25fe2ffe319b9175c
|
7
|
+
data.tar.gz: d5427782a507a555b305578c50354405f89b6307824d810916a529018f392c541f003f3068d96d257fb8d8ea9460bae38b6db176cba33210bbca62edb1636cbb
|
@@ -15,6 +15,8 @@ class PlannedEndpoint
|
|
15
15
|
attr_accessor :method
|
16
16
|
# @return [Integer] HTTP Status code
|
17
17
|
attr_accessor :status_code
|
18
|
+
# @return [Integer] Delay before responding
|
19
|
+
attr_accessor :delay
|
18
20
|
|
19
21
|
# @return [Array]
|
20
22
|
HTTP_METHODS = %w[get put post patch delete options].freeze
|
@@ -26,6 +28,7 @@ class PlannedEndpoint
|
|
26
28
|
@file = true if not_text?
|
27
29
|
assign_params_from_name
|
28
30
|
self.method ||= GlobalSettings.default_method
|
31
|
+
self.delay ||= 0
|
29
32
|
return if status_code
|
30
33
|
|
31
34
|
set_default_status_code
|
@@ -71,6 +74,7 @@ class PlannedEndpoint
|
|
71
74
|
def assign_params_from_name
|
72
75
|
file_parts = filename.split("_")
|
73
76
|
assign_method_from file_parts
|
77
|
+
assign_delay_from file_parts
|
74
78
|
assign_status_from file_parts
|
75
79
|
end
|
76
80
|
|
@@ -84,9 +88,19 @@ class PlannedEndpoint
|
|
84
88
|
self.status_code = status_parts[0].to_i if status_parts.size == 1
|
85
89
|
end
|
86
90
|
|
91
|
+
# Set status code based on filename
|
92
|
+
def assign_delay_from(file_parts)
|
93
|
+
delay_parts = file_parts.find_all { |part| part.start_with?('delay') }
|
94
|
+
if delay_parts.size > 1
|
95
|
+
raise FileSv::FileNameError, "Filename #{filename} has more than 1 delay #{delay_parts}"
|
96
|
+
end
|
97
|
+
|
98
|
+
self.delay = delay_parts[0][5..-1].to_i if delay_parts.size == 1
|
99
|
+
end
|
100
|
+
|
87
101
|
# Set REST method used based on filename
|
88
102
|
def assign_method_from(file_parts)
|
89
|
-
method_parts = file_parts.find_all { |
|
103
|
+
method_parts = file_parts.find_all { |part| HTTP_METHODS.include? part }
|
90
104
|
if method_parts.size > 1
|
91
105
|
raise FileSv::FileNameError, "Filename #{filename} has more than 1 REST methods #{method_parts}"
|
92
106
|
end
|
@@ -112,4 +126,10 @@ class PlannedEndpoint
|
|
112
126
|
def render_text(binding)
|
113
127
|
ERB.new(File.read(serving_file_name)).result(binding)
|
114
128
|
end
|
129
|
+
|
130
|
+
def short_description
|
131
|
+
desc = self.status_code.to_s
|
132
|
+
desc += " (delay #{self.delay} sec)" if self.delay > 0
|
133
|
+
return desc
|
134
|
+
end
|
115
135
|
end
|
data/lib/file_sv/sv_plan.rb
CHANGED
@@ -69,9 +69,9 @@ Serving based on folder: #{Dir.pwd}. Related to folder executed: #{serving_folde
|
|
69
69
|
|
70
70
|
private
|
71
71
|
|
72
|
-
# @return [String]
|
72
|
+
# @return [String] Message to description all endpoints for a method undera endpoint
|
73
73
|
def description_message(method_name, endpoints)
|
74
|
-
" #{method_name.upcase} (#{endpoints.size} responses) #{endpoints.collect(&:
|
74
|
+
" #{method_name.upcase} (#{endpoints.size} responses) #{endpoints.collect(&:short_description)}\n"
|
75
75
|
end
|
76
76
|
end
|
77
77
|
end
|
data/lib/file_sv/version.rb
CHANGED
@@ -37,6 +37,10 @@ for more details'
|
|
37
37
|
content_type :json
|
38
38
|
elsif endpoint.file_path.end_with? '.xml'
|
39
39
|
content_type :xml
|
40
|
+
elsif endpoint.file_path.end_with? '.css'
|
41
|
+
content_type :css
|
42
|
+
elsif endpoint.file_path.end_with? '.js'
|
43
|
+
content_type :js
|
40
44
|
end
|
41
45
|
end
|
42
46
|
|
@@ -50,6 +54,7 @@ for more details'
|
|
50
54
|
message += " Using param '#{@id}'" if id
|
51
55
|
puts message
|
52
56
|
end
|
57
|
+
sleep endpoint.delay if endpoint.delay > 0
|
53
58
|
[endpoint.status_code, output_for(endpoint, binding)]
|
54
59
|
end
|
55
60
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: file_sv
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samuel Garratt
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-03-
|
11
|
+
date: 2024-03-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faker
|
@@ -138,7 +138,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
138
138
|
- !ruby/object:Gem::Version
|
139
139
|
version: '0'
|
140
140
|
requirements: []
|
141
|
-
rubygems_version: 3.
|
141
|
+
rubygems_version: 3.2.3
|
142
142
|
signing_key:
|
143
143
|
specification_version: 4
|
144
144
|
summary: REST service virtualisation through file structure.
|