file_sv 0.1.10 → 0.1.12

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: 1f3dee5f4fc52defa4ee2156a4b55a99d451096a9f306649447d4284cc7762c0
4
- data.tar.gz: d7e6529719bd1cb331608774478b512027184dff994a5ae2037cb704c102cfb9
3
+ metadata.gz: 72954e0e4bfe4eda783ccb40b4219bcd7a915a86c328e9157625c9151d085de4
4
+ data.tar.gz: e250a4b0320757bc1577a538be9e59c72ec12a25f4b3a4e442bde182784a3cdc
5
5
  SHA512:
6
- metadata.gz: 5342a57f1dc12b968065b1d2558a25a17a8178bc36e7d0c3d1c48a67520dea9ea5ffeae8c09240e2ea29a7ae75cee8af2d0c463298713976dcefdb54c30a4b00
7
- data.tar.gz: 44dfc851b979dd6c9cad3a05a531efaf87a8bf31da6d329c01bb40201bca0a6d2e97f8bd8ba3eb1c0aed6e33a5a000a081a7990f1159b334e760a647f3dbc8c3
6
+ metadata.gz: 9b3c6837fcb24dcad7355cf32f7c2f868393935224f32826ee5d585e522fdd07ddb42d8d761362ead1ed997cc4eb88550e30c3dc569a3affd4ae088034364ffb
7
+ data.tar.gz: 42f8f2b8c2a149ebbdb61924dd3aaede4797da0dc3ebb3ab13945bc7cc719f3b3e32330b546c927320e3dd42c6d951ad5ac99adefcdf271f9eecf1d85e79060a
data/exe/file_sv CHANGED
@@ -6,16 +6,23 @@ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), "..", "lib")
6
6
 
7
7
  # Executable for Generic Test
8
8
  class Exe < Thor
9
+ def self.exit_on_failure?
10
+ true
11
+ end
12
+
9
13
  desc "plan folder", "Show plan for service virtualization based on folder"
10
- def plan(folder)
14
+ def plan(folder = nil)
11
15
  require "file_sv"
16
+ if (!folder && GlobalSettings.serving_folder)
17
+ folder = GlobalSettings.serving_folder unless folder
18
+ end
12
19
  ServiceLoader.create_plan_for folder
13
20
  end
14
21
 
15
22
  option :crt, default: nil, banner: "HTTPS CRT"
16
23
  option :key, default: nil, banner: "HTTPS key"
17
24
  desc "serve folder", "Serve virtual service based on folder"
18
- def serve(folder)
25
+ def serve(folder = nil)
19
26
  plan folder
20
27
  ServiceLoader.serve_plan options
21
28
  end
@@ -10,6 +10,8 @@ class GlobalSettings
10
10
 
11
11
  @https = false
12
12
 
13
+ @serving_folder = '.'
14
+
13
15
  @ignore_status_codes = nil
14
16
  class << self
15
17
  # @return [String] Default REST method when none specified by filename
@@ -26,6 +28,8 @@ class GlobalSettings
26
28
  attr_accessor :key
27
29
  # @return [Array] List of http status codes to ignore
28
30
  attr_accessor :ignore_status_codes
31
+ # @return [String] Path from current location to serve folders from
32
+ attr_accessor :serving_folder
29
33
 
30
34
  # @param [Integer] status_code HTTP status code
31
35
  # @return [Boolean] Whether status code is currently ignored
@@ -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 { |pa| HTTP_METHODS.include? pa }
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
@@ -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(&:status_code)}\n"
74
+ " #{method_name.upcase} (#{endpoints.size} responses) #{endpoints.collect(&:short_description)}\n"
75
75
  end
76
76
  end
77
77
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module FileSv
4
- VERSION = "0.1.10"
4
+ VERSION = "0.1.12"
5
5
  end
@@ -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.10
4
+ version: 0.1.12
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-19 00:00:00.000000000 Z
11
+ date: 2024-03-22 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.1.4
141
+ rubygems_version: 3.5.3
142
142
  signing_key:
143
143
  specification_version: 4
144
144
  summary: REST service virtualisation through file structure.