class SvPlan
Holds plan of what virtual service will look like
Attributes
endpoints[R]
@return [Hash] Endpoints included in plan. Key - endpoint, value - methods served under it
serving_folder[RW]
@return [String] Folder plan is served from
Public Class Methods
+(other)
click to toggle source
Add endpoint to plan @param [PlannedEndpoint] other Endpoint to add to plan
# File lib/file_sv/sv_plan.rb, line 56 def +(other) @endpoints[other.path] ||= {} @endpoints[other.path][other.method] ||= [] @endpoints[other.path][other.method] << other end
create(folder)
click to toggle source
Create a plan new plan for a virtual service
# File lib/file_sv/sv_plan.rb, line 15 def create(folder) self.serving_folder = folder puts "Creating service based on files in #{folder}" file_list = Dir.glob("#{folder}/**/*.*") - Dir.glob("#{folder}/#{GlobalSettings.ignore_files}") file_list.each { |file| process_file file } end
inspect()
click to toggle source
Inspect details
# File lib/file_sv/sv_plan.rb, line 50 def inspect "Endpoints: #{endpoints.inspect}" end
process_file(filename)
click to toggle source
Process file, for the most part creating endpoint.method from it @param [String] filename Path to file to process
# File lib/file_sv/sv_plan.rb, line 24 def process_file(filename) filename.slice! serving_folder extension = File.extname(filename) case extension when ".yaml" then YamlProcessor.process(filename) else FileProcessor.process(filename) end end
show()
click to toggle source
Show plan
# File lib/file_sv/sv_plan.rb, line 35 def show endpoint_desc = "" endpoints.sort { |a, b| a[0].casecmp b[0] }.each do |endpoint, methods| endpoint_desc += "#{endpoint} \n" methods.each do |method_name, endpoints| endpoint_desc += description_message method_name, endpoints end end "** VIRTUAL SERVICE PLAN ** Serving based on folder: #{Dir.pwd}. Related to folder executed: #{serving_folder} #{endpoint_desc}" end
Private Class Methods
description_message(method_name, endpoints)
click to toggle source
@return [String]
# File lib/file_sv/sv_plan.rb, line 65 def description_message(method_name, endpoints) " #{method_name.upcase} (#{endpoints.size} responses) #{endpoints.collect(&:status_code)}\n" end