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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 43425956ba3f1325aa81876eea311cabd364f35ae2735adf79f4cb2daed69dd4
4
- data.tar.gz: 629f16289572cb0407ae010a5322f96b07ab6261e591b55dd080f3c9d5e5b58c
3
+ metadata.gz: 1f3dee5f4fc52defa4ee2156a4b55a99d451096a9f306649447d4284cc7762c0
4
+ data.tar.gz: d7e6529719bd1cb331608774478b512027184dff994a5ae2037cb704c102cfb9
5
5
  SHA512:
6
- metadata.gz: ec1ca5bffdfcbcc83f94cde7838bc1cdccf844c6c58f45a768203f8d72f2c77e0ce49f706ba7878cb9ba414a58863fb7438e056d76c341a16b258e6de31d3125
7
- data.tar.gz: c8e605801443bbd947769ce32bfd376daad28c98bf05dcbca4e1cbbf81a09d1b6a50b9a5f6d0dc1aab29d494f6796bf400bbda023e95ddb8e57c3e241bf16692
6
+ metadata.gz: 5342a57f1dc12b968065b1d2558a25a17a8178bc36e7d0c3d1c48a67520dea9ea5ffeae8c09240e2ea29a7ae75cee8af2d0c463298713976dcefdb54c30a4b00
7
+ data.tar.gz: 44dfc851b979dd6c9cad3a05a531efaf87a8bf31da6d329c01bb40201bca0a6d2e97f8bd8ba3eb1c0aed6e33a5a000a081a7990f1159b334e760a647f3dbc8c3
@@ -6,7 +6,7 @@ class GlobalSettings
6
6
 
7
7
  @empty_body_status = 204
8
8
 
9
- @ignore_files = "{*.md,Dockerfile,.*}"
9
+ @ignore_files = "{*.md,Dockerfile}"
10
10
 
11
11
  @https = false
12
12
 
@@ -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
@@ -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 { |file| process_file file }
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module FileSv
4
- VERSION = "0.1.7"
4
+ VERSION = "0.1.10"
5
5
  end
@@ -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.7
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: 2021-12-09 00:00:00.000000000 Z
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