file_sv 0.1.7 → 0.1.10
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/global_settings.rb +1 -1
- data/lib/file_sv/service_loader.rb +1 -1
- data/lib/file_sv/sv_plan.rb +10 -2
- data/lib/file_sv/version.rb +1 -1
- data/lib/file_sv/virtual_server.rb +9 -0
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1f3dee5f4fc52defa4ee2156a4b55a99d451096a9f306649447d4284cc7762c0
|
4
|
+
data.tar.gz: d7e6529719bd1cb331608774478b512027184dff994a5ae2037cb704c102cfb9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5342a57f1dc12b968065b1d2558a25a17a8178bc36e7d0c3d1c48a67520dea9ea5ffeae8c09240e2ea29a7ae75cee8af2d0c463298713976dcefdb54c30a4b00
|
7
|
+
data.tar.gz: 44dfc851b979dd6c9cad3a05a531efaf87a8bf31da6d329c01bb40201bca0a6d2e97f8bd8ba3eb1c0aed6e33a5a000a081a7990f1159b334e760a647f3dbc8c3
|
@@ -3,7 +3,7 @@
|
|
3
3
|
# Responsible for loading all files in service directory and creating service
|
4
4
|
module ServiceLoader
|
5
5
|
# @return [String] Folder where service served from
|
6
|
-
@serving_folder = ""
|
6
|
+
@serving_folder = "."
|
7
7
|
|
8
8
|
class << self
|
9
9
|
# Create virtual service plan based on folder
|
data/lib/file_sv/sv_plan.rb
CHANGED
@@ -5,18 +5,26 @@ require_relative "file_processor"
|
|
5
5
|
# Holds plan of what virtual service will look like
|
6
6
|
class SvPlan
|
7
7
|
@endpoints = {}
|
8
|
+
@file_list = []
|
8
9
|
class << self
|
9
10
|
# @return [Hash] Endpoints included in plan. Key - endpoint, value - methods served under it
|
10
11
|
attr_reader :endpoints
|
11
12
|
# @return [String] Folder plan is served from
|
12
13
|
attr_accessor :serving_folder
|
13
14
|
|
15
|
+
# @return [String] List of files plan is built from
|
16
|
+
attr_accessor :file_list
|
17
|
+
|
14
18
|
# Create a plan new plan for a virtual service
|
15
19
|
def create(folder)
|
16
20
|
self.serving_folder = folder
|
17
21
|
puts "Creating service based on files in #{folder}"
|
18
|
-
file_list = Dir.glob("#{folder}/**/*.*") - Dir.glob("#{folder}/#{GlobalSettings.ignore_files}")
|
19
|
-
file_list.each
|
22
|
+
file_list = Dir.glob("#{folder}/**/*.*", File::FNM_DOTMATCH) - Dir.glob("#{folder}/#{GlobalSettings.ignore_files}", File::FNM_DOTMATCH)
|
23
|
+
file_list.each do |file|
|
24
|
+
next if File.directory? file
|
25
|
+
SvPlan.file_list << file
|
26
|
+
process_file file
|
27
|
+
end
|
20
28
|
end
|
21
29
|
|
22
30
|
# Process file, for the most part creating endpoint.method from it
|
data/lib/file_sv/version.rb
CHANGED
@@ -32,10 +32,19 @@ for more details'
|
|
32
32
|
endpoint.file? ? send_file(endpoint.serving_file_name) : endpoint.content(binding)
|
33
33
|
end
|
34
34
|
|
35
|
+
def append_content_type(endpoint)
|
36
|
+
if (endpoint.file_path.end_with? '.json')
|
37
|
+
content_type :json
|
38
|
+
elsif endpoint.file_path.end_with? '.xml'
|
39
|
+
content_type :xml
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
35
43
|
# Log endpoint. Return content and status code defined by endpoint
|
36
44
|
# @param [PlannedEndpoint] endpoint Planned endpoint to serve
|
37
45
|
def serve(endpoint, id = nil)
|
38
46
|
@id = id
|
47
|
+
append_content_type(endpoint)
|
39
48
|
if ENV['debug'] == "true"
|
40
49
|
message = "Using endpoint based on file #{endpoint.serving_file_name}."
|
41
50
|
message += " Using param '#{@id}'" if id
|
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.10
|
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: 2024-03-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faker
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rackup
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: sinatra
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|