Class: RspecStarter::Options

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec_starter/options.rb

Overview

Manages the option registration process for the Step subclasses. Holds raw option information so it can organized when steps run.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(environment, args) ⇒ Options

Returns a new instance of Options.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/rspec_starter/options.rb', line 7

def initialize(environment, args)
  @environment = environment
  # These are the ARGV args that are passed to the command line.
  @command_line_args = args
  # Task classes that are used in the RspecStarter.start block: VerifyDisplayServer, StartRspec, etc...
  @task_classes = environment.unique_task_classes
  # The options that each Task wants to use.
  @registered_task_options = {}

  # Tasks register the command line switches they care about and RspecStarter has some global switches that it uses. This
  # holds the list of switches that the user provided that match a task switch or a global switch. If the user doesn't
  # supply a switch, or supplies a switch that nobody cares about, this will be an empty list.
  @present_switches = nil

  load_registered_task_options
  initialize_present_switches

  # The args that should be passed to rspec when it starts.
  @rspec_args_string = nil
  initialize_rspec_args_string
end

Instance Attribute Details

#present_switchesObject (readonly)

Returns the value of attribute present_switches.



5
6
7
# File 'lib/rspec_starter/options.rb', line 5

def present_switches
  @present_switches
end

#registered_task_optionsObject (readonly)

Returns the value of attribute registered_task_options.



5
6
7
# File 'lib/rspec_starter/options.rb', line 5

def registered_task_options
  @registered_task_options
end

#rspec_args_stringObject (readonly)

Returns the value of attribute rspec_args_string.



5
6
7
# File 'lib/rspec_starter/options.rb', line 5

def rspec_args_string
  @rspec_args_string
end

Instance Method Details

#all_switchesObject



56
57
58
# File 'lib/rspec_starter/options.rb', line 56

def all_switches
  (global_switches + all_task_switches).sort
end

#all_task_optionsObject



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

def all_task_options
  hash = {}
  @registered_task_options.each_value do |options|
    options.each do |option|
      hash[option.switch] = option unless hash.has_key?(option.switch)
    end
  end

  list = []
  hash.each_value { |option| list << option }
  list
end

#all_task_switchesObject



64
65
66
67
68
69
70
# File 'lib/rspec_starter/options.rb', line 64

def all_task_switches
  list = Set.new
  @registered_task_options.each_value do |options|
    options.each { |option| list << option.switch unless option.switch.nil? }
  end
  list.to_a
end

#global_switchesObject



60
61
62
# File 'lib/rspec_starter/options.rb', line 60

def global_switches
  ['--help', '-h']
end

#register_task_option(klass, name: nil, default: nil, description: "", switch: nil, switch_description: "") ⇒ Object

If name isn’t specified, this option is only a commandline switch. If name is specified, this option can be used inside the start block on a task.



37
38
39
40
41
# File 'lib/rspec_starter/options.rb', line 37

def register_task_option(klass, name: nil, default: nil, description: "", switch: nil, switch_description: "")
  new_option = RspecStarter::Option.new(name: name, default: default, description: description, owner: klass, switch: switch,
    switch_description: switch_description)
  @registered_task_options[klass] << new_option
end

#registered_task_option(task_class) ⇒ Object



72
73
74
# File 'lib/rspec_starter/options.rb', line 72

def registered_task_option(task_class)
  @registered_task_options[task_class]
end