file_sv 0.1.2 → 0.1.3
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.rb +10 -11
- data/lib/file_sv/global_settings.rb +10 -0
- data/lib/file_sv/planned_endpoint.rb +2 -0
- data/lib/file_sv/sv_plan.rb +9 -10
- data/lib/file_sv/version.rb +1 -1
- data/lib/file_sv/virtual_server.rb +6 -5
- data/lib/file_sv/yaml_processor.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b8c717829a4044f5970f099311a51d86317e009cb04d01e2b596e2ac24ee5296
|
4
|
+
data.tar.gz: 64a21579ccd9c87ea14a0e8b634f9095450cea66167ef0d414bff97e77f7ce3f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 594bfe0862c82585f8568cf3a46d2952bd631bf6795fd7b518a74a4b578eb9eab500523016602110f5ca60094f9a53bfe91c395970ad3ca5774d3d51f2a8427e
|
7
|
+
data.tar.gz: dd153f38c16a882d3ff806dcec71a7b798e7578aea0fe5322f868ea77bd6af7958e7eefc23b47e31f18bb35a78c869e0386155b7936e62086e07411734a2a9ab
|
data/lib/file_sv.rb
CHANGED
@@ -15,10 +15,11 @@ module FileSv
|
|
15
15
|
class FileNameError < Error; end
|
16
16
|
|
17
17
|
class << self
|
18
|
+
# @return [Hash] Mapping of REST method names to setting classes
|
18
19
|
def rest_methods
|
19
20
|
{
|
20
21
|
get: GetSettings, post: PostSettings, patch: PatchSettings, options: OptionsSettings,
|
21
|
-
delete: DeleteSettings
|
22
|
+
delete: DeleteSettings, put: PutSettings
|
22
23
|
}
|
23
24
|
end
|
24
25
|
end
|
@@ -29,17 +30,15 @@ CONFIG_FILE = "file_sv.yaml"
|
|
29
30
|
# Set values in global settings based on config
|
30
31
|
def load_default_config(file_path)
|
31
32
|
require "yaml"
|
32
|
-
|
33
|
-
config = YAML.load_file file_path
|
34
|
-
config["global"]&.each do |key, value|
|
35
|
-
GlobalSettings.send("#{key}=", value)
|
36
|
-
end
|
33
|
+
return unless File.exist? file_path
|
37
34
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
35
|
+
config = YAML.load_file file_path
|
36
|
+
config["global"]&.each do |key, value|
|
37
|
+
GlobalSettings.send("#{key}=", value)
|
38
|
+
end
|
39
|
+
|
40
|
+
FileSv.rest_methods.each do |method, setting_class|
|
41
|
+
config[method.to_s]&.each { |key, value| setting_class.send("#{key}=", value) }
|
43
42
|
end
|
44
43
|
end
|
45
44
|
|
@@ -5,11 +5,15 @@ class GlobalSettings
|
|
5
5
|
@default_method = "get"
|
6
6
|
|
7
7
|
@empty_body_status = 204
|
8
|
+
|
9
|
+
@ignore_files = "{*.md,Dockerfile,.*}"
|
8
10
|
class << self
|
9
11
|
# @return [String] Default REST method when none specified by filename
|
10
12
|
attr_accessor :default_method
|
11
13
|
# @return [Integer] Default status of response when file is empty
|
12
14
|
attr_accessor :empty_body_status
|
15
|
+
# @return [Array] Expression representing files to ignore
|
16
|
+
attr_accessor :ignore_files
|
13
17
|
end
|
14
18
|
end
|
15
19
|
|
@@ -35,6 +39,12 @@ class PatchSettings
|
|
35
39
|
extend CommonHttpSettings
|
36
40
|
end
|
37
41
|
|
42
|
+
# Settings specific to PATCH
|
43
|
+
class PutSettings
|
44
|
+
@default_status = 200
|
45
|
+
extend CommonHttpSettings
|
46
|
+
end
|
47
|
+
|
38
48
|
# Settings specific to OPTIONS
|
39
49
|
class OptionsSettings
|
40
50
|
@default_status = 200
|
@@ -35,6 +35,7 @@ class PlannedEndpoint
|
|
35
35
|
@file
|
36
36
|
end
|
37
37
|
|
38
|
+
# Return default status code for an empty body
|
38
39
|
def default_empty_code
|
39
40
|
return false if not_text?
|
40
41
|
|
@@ -45,6 +46,7 @@ class PlannedEndpoint
|
|
45
46
|
false
|
46
47
|
end
|
47
48
|
|
49
|
+
# Set default status code based on empty body or type of METHOD
|
48
50
|
def set_default_status_code
|
49
51
|
return if default_empty_code
|
50
52
|
|
data/lib/file_sv/sv_plan.rb
CHANGED
@@ -15,27 +15,26 @@ class SvPlan
|
|
15
15
|
def create(folder)
|
16
16
|
self.serving_folder = folder
|
17
17
|
puts "Creating service based on files in #{folder}"
|
18
|
-
file_list = Dir.glob("#{folder}/**/*.*")
|
19
|
-
file_list.each
|
20
|
-
process_file file
|
21
|
-
end
|
18
|
+
file_list = Dir.glob("#{folder}/**/*.*") - Dir.glob(GlobalSettings.ignore_files)
|
19
|
+
file_list.each { |file| process_file file }
|
22
20
|
end
|
23
21
|
|
24
22
|
# Process file, for the most part creating endpoint.method from it
|
25
|
-
|
26
|
-
|
27
|
-
|
23
|
+
# @param [String] filename Path to file to process
|
24
|
+
def process_file(filename)
|
25
|
+
filename.slice! serving_folder
|
26
|
+
extension = File.extname(filename)
|
28
27
|
case extension
|
29
|
-
when ".yaml" then YamlProcessor.process(
|
28
|
+
when ".yaml" then YamlProcessor.process(filename)
|
30
29
|
else
|
31
|
-
FileProcessor.process(
|
30
|
+
FileProcessor.process(filename)
|
32
31
|
end
|
33
32
|
end
|
34
33
|
|
35
34
|
# Show plan
|
36
35
|
def show
|
37
36
|
endpoint_desc = ""
|
38
|
-
endpoints.sort { |a,b| a[0].length - b[0].length
|
37
|
+
endpoints.sort { |a, b| a[0].length - b[0].length }.each do |endpoint, methods|
|
39
38
|
endpoint_desc += "#{endpoint} \n"
|
40
39
|
methods.each do |method_name, endpoints|
|
41
40
|
endpoint_desc += " #{method_name.upcase} (#{endpoints.size} responses)\n"
|
data/lib/file_sv/version.rb
CHANGED
@@ -12,16 +12,17 @@ class VirtualServer < Sinatra::Base
|
|
12
12
|
register Sinatra::DocDsl
|
13
13
|
|
14
14
|
page do
|
15
|
-
title
|
15
|
+
title "File SV"
|
16
16
|
header "Service virtualization created from #{Dir.pwd}"
|
17
|
-
introduction 'Created using file_sv. See <a href="https://gitlab.com/samuel-garratt/file_sv">File SV</a>
|
17
|
+
introduction 'Created using file_sv. See <a href="https://gitlab.com/samuel-garratt/file_sv">File SV</a>
|
18
|
+
for more details'
|
18
19
|
end
|
19
20
|
|
20
|
-
get
|
21
|
-
send_file File.join(__dir__,
|
21
|
+
get "/favicon.ico" do
|
22
|
+
send_file File.join(__dir__, "file_sv.ico")
|
22
23
|
end
|
23
24
|
|
24
|
-
doc_endpoint
|
25
|
+
doc_endpoint "/docs"
|
25
26
|
|
26
27
|
SvPlan.endpoints.each do |_endpoint_path, endpoint_value|
|
27
28
|
endpoint_value.each do |_method_name, endpoints|
|
@@ -6,7 +6,7 @@ class YamlProcessor
|
|
6
6
|
# Process YAML file
|
7
7
|
def process(filename)
|
8
8
|
if filename == "/file_sv.yaml"
|
9
|
-
puts "Overriding default config based on #{Dir.pwd
|
9
|
+
puts "Overriding default config based on #{File.join(Dir.pwd, filename[1..-1])}"
|
10
10
|
load_default_config filename[1..-1]
|
11
11
|
else
|
12
12
|
puts "Skipping #{filename}"
|
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.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samuel Garratt
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-03-
|
11
|
+
date: 2021-03-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faker
|