Class: SvPlan

Inherits:
Object
  • Object
show all
Defined in:
lib/file_sv/sv_plan.rb

Overview

Holds plan of what virtual service will look like

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.endpointsHash (readonly)

Returns Endpoints included in plan. Key - endpoint, value - methods served under it.

Returns:

  • (Hash)

    Endpoints included in plan. Key - endpoint, value - methods served under it



11
12
13
# File 'lib/file_sv/sv_plan.rb', line 11

def endpoints
  @endpoints
end

.file_listString

Returns List of files plan is built from.

Returns:

  • (String)

    List of files plan is built from



16
17
18
# File 'lib/file_sv/sv_plan.rb', line 16

def file_list
  @file_list
end

.serving_folderString

Returns Folder plan is served from.

Returns:

  • (String)

    Folder plan is served from



13
14
15
# File 'lib/file_sv/sv_plan.rb', line 13

def serving_folder
  @serving_folder
end

Class Method Details

.+(other) ⇒ Object

Add endpoint to plan

Parameters:



64
65
66
67
68
# File 'lib/file_sv/sv_plan.rb', line 64

def +(other)
  @endpoints[other.path] ||= {}
  @endpoints[other.path][other.method] ||= []
  @endpoints[other.path][other.method] << other
end

.create(folder) ⇒ Object

Create a plan new plan for a virtual service



19
20
21
22
23
24
25
26
27
28
# File 'lib/file_sv/sv_plan.rb', line 19

def create(folder)
  self.serving_folder = folder
  puts "Creating service based on files in #{folder}"
  file_list = Dir.glob("#{folder}/**/*.*", File::FNM_DOTMATCH) - Dir.glob("#{folder}/#{GlobalSettings.ignore_files}", File::FNM_DOTMATCH)        
  file_list.each do |file| 
    next if File.directory? file
    SvPlan.file_list << file
    process_file file
  end
end

.inspectObject

Inspect details



58
59
60
# File 'lib/file_sv/sv_plan.rb', line 58

def inspect
  "Endpoints: #{endpoints.inspect}"
end

.process_file(filename) ⇒ Object

Process file, for the most part creating endpoint.method from it

Parameters:

  • filename (String)

    Path to file to process



32
33
34
35
36
37
38
39
40
# File 'lib/file_sv/sv_plan.rb', line 32

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

.showObject

Show plan



43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/file_sv/sv_plan.rb', line 43

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