Class: Jasmine::Headless::Options

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/jasmine/headless/options.rb

Constant Summary collapse

DEFAULT_OPTIONS =
{
  :colors => false,
  :remove_html_file => true,
  :runner_output_filename => false,
  :jasmine_config => 'spec/javascripts/support/jasmine.yml',
  :report => false,
  :do_list => false,
  :full_run => true,
  :enable_cache => true,
  :files => []
}
DEFAULTS_FILE =
File.join(Dir.pwd, '.jasmine-headless-webkit')
GLOBAL_DEFAULTS_FILE =
File.expand_path('~/.jasmine-headless-webkit')

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Options

Returns a new instance of Options.



33
34
35
36
37
38
39
# File 'lib/jasmine/headless/options.rb', line 33

def initialize(opts = {})
  @options = DEFAULT_OPTIONS.dup
  srand
  @options[:seed] = rand(10000)
  read_defaults_files
  opts.each { |k, v| @options[k] = v if v }
end

Class Method Details

.from_command_lineObject



26
27
28
29
30
31
# File 'lib/jasmine/headless/options.rb', line 26

def self.from_command_line
  options = new
  options.process_command_line_args
  options[:files] = ARGV
  options
end

Instance Method Details

#process_command_line_argsObject



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/jasmine/headless/options.rb', line 78

def process_command_line_args
  command_line_args = GetoptLong.new(
    [ '--colors', '-c', GetoptLong::NO_ARGUMENT ],
    [ '--no-colors', GetoptLong::NO_ARGUMENT ],
    [ '--cache', GetoptLong::NO_ARGUMENT ],
    [ '--no-t stcache', GetoptLong::NO_ARGUMENT ],
    [ '--keep', GetoptLong::NO_ARGUMENT ],
    [ '--runner-out', GetoptLong::REQUIRED_ARGUMENT ],
    [ '--report', GetoptLong::REQUIRED_ARGUMENT ],
    [ '--jasmine-config', '-j', GetoptLong::REQUIRED_ARGUMENT ],
    [ '--no-full-run', GetoptLong::NO_ARGUMENT ],
    [ '--list', '-l', GetoptLong::NO_ARGUMENT ],
    [ '--seed', GetoptLong::REQUIRED_ARGUMENT ]
  )

  command_line_args.each { |*args| process_option(*args) }
end

#process_option(*args) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/jasmine/headless/options.rb', line 41

def process_option(*args)
  opt, arg = args.flatten[0..1]

  case opt
  when '--colors', '-c'
    @options[:colors] = true
  when '--no-colors', '-nc'
    @options[:colors] = false
  when '--cache'
    @options[:enable_cache] = true
  when '--no-cache'
    @options[:enable_cache] = false
  when '--keep'
    @options[:remove_html_file] = false
  when '--report'
    @options[:report] = arg
  when '--runner-out'
    @options[:runner_output_filename] = arg
  when '--jasmine-config', '-j'
    @options[:jasmine_config] = arg
  when '--no-full-run'
    @options[:full_run] = false
  when '--list', '-l'
    @options[:do_list] = true
  when '--seed'
    @options[:seed] = arg.to_i
  end
end

#read_defaults_filesObject



70
71
72
73
74
75
76
# File 'lib/jasmine/headless/options.rb', line 70

def read_defaults_files
  [ GLOBAL_DEFAULTS_FILE, DEFAULTS_FILE ].each do |file|
    if File.file?(file)
      File.readlines(file).collect { |line| line.strip.split(' ', 2) }.each { |*args| process_option(*args) }
    end
  end
end