Class: SimpleTestRunner::RunnerOpts
- Inherits:
-
Object
- Object
- SimpleTestRunner::RunnerOpts
- Defined in:
- lib/simple_test_runner/runner_opts.rb
Instance Method Summary collapse
- #config_file_name ⇒ Object
- #config_file_name=(filename) ⇒ Object
- #configfileok ⇒ Object
-
#initialize(args, path = "") ⇒ RunnerOpts
constructor
A new instance of RunnerOpts.
- #load_config_file ⇒ Object
- #load_yaml(yaml_string) ⇒ Object
- #parse(args) ⇒ Object
- #parsed ⇒ Object
- #parsed=(val) ⇒ Object
- #print_usage ⇒ Object
- #save_to_file ⇒ Object
- #show_config ⇒ Object
- #to_yaml ⇒ Object
Constructor Details
#initialize(args, path = "") ⇒ RunnerOpts
Returns a new instance of RunnerOpts.
7 8 9 10 11 12 13 |
# File 'lib/simple_test_runner/runner_opts.rb', line 7 def initialize(args, path="") @parsed = OpenStruct.new parse(args) # if not path == "" # @parsed.dirs_to_monitor = "" # end end |
Instance Method Details
#config_file_name ⇒ Object
49 50 51 |
# File 'lib/simple_test_runner/runner_opts.rb', line 49 def config_file_name ".simpletestrunnerrc" end |
#config_file_name=(filename) ⇒ Object
26 27 28 |
# File 'lib/simple_test_runner/runner_opts.rb', line 26 def config_file_name= filename @parsed.config_file_name = filename end |
#configfileok ⇒ Object
53 54 55 |
# File 'lib/simple_test_runner/runner_opts.rb', line 53 def configfileok File.exists? config_file_name end |
#load_config_file ⇒ Object
44 45 46 47 |
# File 'lib/simple_test_runner/runner_opts.rb', line 44 def load_config_file yaml = File.new(config_file_name).read load_yaml yaml end |
#load_yaml(yaml_string) ⇒ Object
15 16 17 18 19 20 |
# File 'lib/simple_test_runner/runner_opts.rb', line 15 def load_yaml yaml_string yaml = YAML::load(yaml_string) @parsed.command = yaml["command"] puts "load_yaml: yaml = #{yaml.inspect}" end |
#parse(args) ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/simple_test_runner/runner_opts.rb', line 69 def parse args @parsed.verbose ||= false @parsed.make_config_file ||= false @parsed.show_config ||= false @parsed.dirs_to_monitor ||= [] @parsed.ok ||= false @parsed.command_str ||= "echo 'Dir changed'" @parsed.fake ||= false @optionParser = OptionParser.new do |opts| opts. = "Usage: simple_test_runner [options]" # Command to run opts.on("-c", "--command COMMAND", String, "Command to run") do |commandstr| @parsed.command_str = commandstr @parsed.ok = true end # Create a config file # opts.on("-C", "--configfile", "create a config file") do # @parsed.make_config_file = true # @parsed.ok = true # end # List of dirs. opts.on("-d", "--dirs x,y,z", Array, "example 'list' of arguments") do |list| @parsed.dirs_to_monitor = list @parsed.ok = true end # fake run opts.on("-f", "--fake", "Fake run: don't actually monitor the dirs") do @parsed.fake = true end # show help opts.on('-h', "--help", "Print out this message") do |url| puts opts @parsed.ok = true end # Show configuration opts.on('-s', '--show', 'Show the current configuration') do |password| @parsed.show_config = true @parsed.ok = true end end @optionParser.parse!(args) @parsed end |
#parsed ⇒ Object
34 35 36 |
# File 'lib/simple_test_runner/runner_opts.rb', line 34 def parsed @parsed end |
#parsed=(val) ⇒ Object
30 31 32 |
# File 'lib/simple_test_runner/runner_opts.rb', line 30 def parsed= val @parsed = val end |
#print_usage ⇒ Object
57 58 59 |
# File 'lib/simple_test_runner/runner_opts.rb', line 57 def print_usage puts @optionParser end |
#save_to_file ⇒ Object
38 39 40 41 42 |
# File 'lib/simple_test_runner/runner_opts.rb', line 38 def save_to_file File.open(@parsed.config_file_name, 'w+') do |file| file.puts to_yaml end end |
#show_config ⇒ Object
61 62 63 64 65 66 67 |
# File 'lib/simple_test_runner/runner_opts.rb', line 61 def show_config puts "Configuration:" puts "config file: \"#{config_file_name}\"" puts "dirs to monitor: #{@parsed.dirs_to_monitor.inspect}" puts "command to run: \"#{@parsed.command_str}\"" puts "fake run: #{@parsed.fake}" end |
#to_yaml ⇒ Object
22 23 24 |
# File 'lib/simple_test_runner/runner_opts.rb', line 22 def to_yaml "command: echo 'hello'" end |