Module: NameFileFinder

Defined in:
lib/teuton/project/name_file_finder.rb

Overview

Project:

  • find_filenames_for, verbose, verboseln

Class Method Summary collapse

Class Method Details

.find_configfilename_from_directory(pathtodir) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/teuton/project/name_file_finder.rb', line 43

def self.find_configfilename_from_directory(pathtodir)
  # COMPLEX MODE: We use config.yaml by default
  app = Application.instance

  config_path = ''
  if app.options['cpath'].nil?
    config_name = 'config'
    # Config name file is introduced by cname arg option from teuton command
    config_name = app.options['cname'] unless app.options['cname'].nil?
    config_path = File.join(pathtodir, "#{config_name}.json")
    unless File.exist? config_path
      config_path = File.join(pathtodir, "#{config_name}.yaml")
    end
  else
    # Config path file is introduced by cpath arg option from teuton command
    config_path = app.options['cpath']
  end
  app.config_path = config_path
end

.find_configfilenames_from_rb(script_path) ⇒ Object



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/teuton/project/name_file_finder.rb', line 81

def self.find_configfilenames_from_rb(script_path)
  # SIMPLE MODE: We use script_path as main RB file
  # This must be fullpath to DSL script file
  app = Application.instance

  config_path = ''
  if app.options['cpath'].nil?
    config_name = File.basename(script_path, '.rb')
    # Config name file is introduced by cname arg option from teuton command
    config_name = app.options['cname'] unless app.options['cname'].nil?

    config_path = File.join(app.project_path, config_name + '.json')
    unless File.exist? config_path
      config_path = File.join(app.project_path, config_name + '.yaml')
    end
  else
    # Config path file is introduced by cpath arg option from teuton command
    config_path = app.options['cpath']
  end
  app.config_path = config_path
end

.find_filenames_for(relpathtofile) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/teuton/project/name_file_finder.rb', line 9

def self.find_filenames_for(relpathtofile)
  pathtofile = File.absolute_path(relpathtofile)

  # Define:
  #   script_path, must contain fullpath to DSL script file
  #   config_path, must contain fullpath to YAML config file
  if File.directory?(pathtofile)
    # COMPLEX MODE: We use start.rb as main RB file
    find_filenames_from_directory(pathtofile)
  else
    # SIMPLE MODE: We use pathtofile as main RB file
    find_filenames_from_rb(pathtofile)
  end
  true
end

.find_filenames_from_directory(pathtodir) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/teuton/project/name_file_finder.rb', line 25

def self.find_filenames_from_directory(pathtodir)
  # COMPLEX MODE: We use start.rb as main RB file
  script_path = File.join(pathtodir, 'start.rb')
  unless File.exist? script_path
    print Rainbow('[ERROR] File ').red
    print Rainbow(script_path).bright.red
    puts Rainbow(' not found!').red
    exit 1
  end

  app = Application.instance
  app.project_path = pathtodir
  app.script_path = script_path
  app.test_name = pathtodir.split(File::SEPARATOR)[-1]

  find_configfilename_from_directory(pathtodir)
end

.find_filenames_from_rb(script_path) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/teuton/project/name_file_finder.rb', line 63

def self.find_filenames_from_rb(script_path)
  # SIMPLE MODE: We use script_path as main RB file
  # This must be fullpath to DSL script file
  if File.extname(script_path) != '.rb'
    print Rainbow('[ERROR] Script ').red
    print Rainbow(script_path).bright.red
    puts Rainbow(' must have rb extension').red
    exit 1
  end

  app = Application.instance
  app.project_path = File.dirname(script_path)
  app.script_path = script_path
  app.test_name = File.basename(script_path, '.rb')

  find_configfilenames_from_rb(script_path)
end

.puts_input_info_on_screen ⇒ Object



103
104
105
106
107
108
109
110
111
112
# File 'lib/teuton/project/name_file_finder.rb', line 103

def self.puts_input_info_on_screen
  app = Application.instance

  verbose Rainbow('[INFO] ScriptPath => ').blue
  verboseln Rainbow(trim(app.script_path)).blue.bright
  verbose Rainbow('[INFO] ConfigPath => ').blue
  verboseln Rainbow(trim(app.config_path)).blue.bright
  verbose Rainbow('[INFO] TestName   => ').blue
  verboseln Rainbow(trim(app.test_name)).blue.bright
end

.trim(input) ⇒ Object



114
115
116
117
118
# File 'lib/teuton/project/name_file_finder.rb', line 114

def self.trim(input)
  output = input.to_s
  output = "...#{input[input.size - 50, input.size]}" if output.size > 65
  output.to_s
end

.verbose(text) ⇒ Object



124
125
126
127
128
# File 'lib/teuton/project/name_file_finder.rb', line 124

def self.verbose(text)
  return unless Application.instance.verbose
  return if Application.instance.options['quiet']
  print text
end

.verboseln(text) ⇒ Object



120
121
122
# File 'lib/teuton/project/name_file_finder.rb', line 120

def self.verboseln(text)
  verbose(text + "\n")
end