file_sv 0.1.7 → 0.1.8
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/exe/file_sv +0 -0
- data/lib/file_sv/global_settings.rb +1 -1
- data/lib/file_sv/sv_plan.rb +5 -2
- data/lib/file_sv/version.rb +1 -1
- data/lib/file_sv/yaml_processor.rb +16 -16
- data/lib/file_sv.rb +64 -64
- 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: f0b7afdb64abc1410be6cebdcf263fca4f5d6a1bc3319e499aa2465b494ea144
|
4
|
+
data.tar.gz: f64237aecf384cafc4bc9469ebecd6c3e4958083ebad3a1e5e90959b425e2662
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7df5f1b80d1330a08ea6aafa52ba1d4e3d0d01ae963d276ca0a3ad0bffa4f03333e328955e227a86a4d4d980ae9c4a911ee018fea14cbf5d82ceac6baf5c4cdf
|
7
|
+
data.tar.gz: e6d42d44838e2bb3d44bb1427c904dd1a75bbe400b26d882ed4109ebcdd6ceae1c82ebb33333a6efc0114a647a7e861118f851d536b9461c19ee97b83ae93932
|
data/exe/file_sv
CHANGED
File without changes
|
data/lib/file_sv/sv_plan.rb
CHANGED
@@ -15,8 +15,11 @@ 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}/**/*.*") - Dir.glob("#{folder}/#{GlobalSettings.ignore_files}")
|
19
|
-
file_list.each
|
18
|
+
file_list = Dir.glob("#{folder}/**/*.*", File::FNM_DOTMATCH) - Dir.glob("#{folder}/#{GlobalSettings.ignore_files}, File::FNM_DOTMATCH")
|
19
|
+
file_list.each do |file|
|
20
|
+
next if File.directory? file
|
21
|
+
process_file file
|
22
|
+
end
|
20
23
|
end
|
21
24
|
|
22
25
|
# Process file, for the most part creating endpoint.method from it
|
data/lib/file_sv/version.rb
CHANGED
@@ -1,16 +1,16 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# Process YAML files
|
4
|
-
class YamlProcessor
|
5
|
-
class << self
|
6
|
-
# Process YAML file
|
7
|
-
def process(filename)
|
8
|
-
if filename == "/file_sv.yaml"
|
9
|
-
puts "Overriding default config based on #{File.join(Dir.pwd, filename[1..])}"
|
10
|
-
load_default_config filename[1..]
|
11
|
-
else
|
12
|
-
puts "Skipping #{filename}"
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Process YAML files
|
4
|
+
class YamlProcessor
|
5
|
+
class << self
|
6
|
+
# Process YAML file
|
7
|
+
def process(filename)
|
8
|
+
if filename == "/file_sv.yaml"
|
9
|
+
puts "Overriding default config based on #{File.join(Dir.pwd, filename[1..])}"
|
10
|
+
load_default_config filename[1..]
|
11
|
+
else
|
12
|
+
puts "Skipping #{filename}"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/lib/file_sv.rb
CHANGED
@@ -1,64 +1,64 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "yaml"
|
4
|
-
require_relative "file_sv/version"
|
5
|
-
require_relative "file_sv/global_settings"
|
6
|
-
require_relative "file_sv/sv_plan"
|
7
|
-
require_relative "file_sv/service_loader"
|
8
|
-
require_relative "file_sv/planned_endpoint"
|
9
|
-
|
10
|
-
# Create Service Virtualization from a simple file system
|
11
|
-
module FileSv
|
12
|
-
# General error for FileSv
|
13
|
-
class Error < StandardError; end
|
14
|
-
|
15
|
-
# Error related to incorrect format of filename
|
16
|
-
class FileNameError < Error; end
|
17
|
-
|
18
|
-
class << self
|
19
|
-
# @return [Hash] Mapping of REST method names to setting classes
|
20
|
-
def rest_methods
|
21
|
-
{
|
22
|
-
get: GetSettings, post: PostSettings, patch: PatchSettings, options: OptionsSettings,
|
23
|
-
delete: DeleteSettings, put: PutSettings
|
24
|
-
}
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
CONFIG_FILE = "file_sv.yaml"
|
30
|
-
|
31
|
-
# Set values in global settings based on config
|
32
|
-
def load_default_config(file_path)
|
33
|
-
return unless File.exist? file_path
|
34
|
-
|
35
|
-
config = YAML.load_file file_path
|
36
|
-
return unless config # Handle empty YAML file
|
37
|
-
|
38
|
-
config["global"]&.each do |key, value|
|
39
|
-
GlobalSettings.send("#{key}=", value)
|
40
|
-
end
|
41
|
-
|
42
|
-
load_rest_method_config config
|
43
|
-
end
|
44
|
-
|
45
|
-
# Load details of each REST method
|
46
|
-
def load_rest_method_config(config)
|
47
|
-
FileSv.rest_methods.each do |method, setting_class|
|
48
|
-
config[method.to_s]&.each { |key, value| setting_class.send("#{key}=", value) }
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
# Set global params based on ENV vars
|
53
|
-
def set_based_on_env_vars
|
54
|
-
GlobalSettings.instance_variables.each do |setting|
|
55
|
-
setting_name = setting.to_s[1..]
|
56
|
-
if ENV[setting_name]
|
57
|
-
puts "Setting #{setting_name} to #{ENV[setting_name]}"
|
58
|
-
GlobalSettings.send("#{setting_name}=", ENV[setting_name])
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
load_default_config CONFIG_FILE
|
64
|
-
set_based_on_env_vars
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "yaml"
|
4
|
+
require_relative "file_sv/version"
|
5
|
+
require_relative "file_sv/global_settings"
|
6
|
+
require_relative "file_sv/sv_plan"
|
7
|
+
require_relative "file_sv/service_loader"
|
8
|
+
require_relative "file_sv/planned_endpoint"
|
9
|
+
|
10
|
+
# Create Service Virtualization from a simple file system
|
11
|
+
module FileSv
|
12
|
+
# General error for FileSv
|
13
|
+
class Error < StandardError; end
|
14
|
+
|
15
|
+
# Error related to incorrect format of filename
|
16
|
+
class FileNameError < Error; end
|
17
|
+
|
18
|
+
class << self
|
19
|
+
# @return [Hash] Mapping of REST method names to setting classes
|
20
|
+
def rest_methods
|
21
|
+
{
|
22
|
+
get: GetSettings, post: PostSettings, patch: PatchSettings, options: OptionsSettings,
|
23
|
+
delete: DeleteSettings, put: PutSettings
|
24
|
+
}
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
CONFIG_FILE = "file_sv.yaml"
|
30
|
+
|
31
|
+
# Set values in global settings based on config
|
32
|
+
def load_default_config(file_path)
|
33
|
+
return unless File.exist? file_path
|
34
|
+
|
35
|
+
config = YAML.load_file file_path
|
36
|
+
return unless config # Handle empty YAML file
|
37
|
+
|
38
|
+
config["global"]&.each do |key, value|
|
39
|
+
GlobalSettings.send("#{key}=", value)
|
40
|
+
end
|
41
|
+
|
42
|
+
load_rest_method_config config
|
43
|
+
end
|
44
|
+
|
45
|
+
# Load details of each REST method
|
46
|
+
def load_rest_method_config(config)
|
47
|
+
FileSv.rest_methods.each do |method, setting_class|
|
48
|
+
config[method.to_s]&.each { |key, value| setting_class.send("#{key}=", value) }
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
# Set global params based on ENV vars
|
53
|
+
def set_based_on_env_vars
|
54
|
+
GlobalSettings.instance_variables.each do |setting|
|
55
|
+
setting_name = setting.to_s[1..]
|
56
|
+
if ENV[setting_name]
|
57
|
+
puts "Setting #{setting_name} to #{ENV[setting_name]}"
|
58
|
+
GlobalSettings.send("#{setting_name}=", ENV[setting_name])
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
load_default_config CONFIG_FILE
|
64
|
+
set_based_on_env_vars
|
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.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samuel Garratt
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-01-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faker
|
@@ -124,7 +124,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
124
124
|
- !ruby/object:Gem::Version
|
125
125
|
version: '0'
|
126
126
|
requirements: []
|
127
|
-
rubygems_version: 3.
|
127
|
+
rubygems_version: 3.2.32
|
128
128
|
signing_key:
|
129
129
|
specification_version: 4
|
130
130
|
summary: REST service virtualisation through file structure.
|