Class: RspecStarter::Option

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

Overview

Option objects hold the information that Step subclasses want to register as options.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, default:, owner:, switch:, description: "", switch_description: "") ⇒ Option

Returns a new instance of Option.



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/rspec_starter/option.rb', line 6

def initialize(name:, default:, owner:, switch:, description: "", switch_description: "")
  @owner = owner
  @switch = switch
  @switch_description = switch_description
  @simplified_switch = switch.nil? ? nil : self.class.simplified_switch_name(switch)
  @description = description
  @default = default
  self.name = name
  @key = name || @simplified_switch
  validate
end

Instance Attribute Details

#defaultObject (readonly)

Returns the value of attribute default.



4
5
6
# File 'lib/rspec_starter/option.rb', line 4

def default
  @default
end

#descriptionObject (readonly)

Returns the value of attribute description.



4
5
6
# File 'lib/rspec_starter/option.rb', line 4

def description
  @description
end

#keyObject (readonly)

Returns the value of attribute key.



4
5
6
# File 'lib/rspec_starter/option.rb', line 4

def key
  @key
end

#nameObject

Returns the value of attribute name.



4
5
6
# File 'lib/rspec_starter/option.rb', line 4

def name
  @name
end

#ownerObject (readonly)

Returns the value of attribute owner.



4
5
6
# File 'lib/rspec_starter/option.rb', line 4

def owner
  @owner
end

#switchObject (readonly)

Returns the value of attribute switch.



4
5
6
# File 'lib/rspec_starter/option.rb', line 4

def switch
  @switch
end

#switch_descriptionObject (readonly)

Returns the value of attribute switch_description.



4
5
6
# File 'lib/rspec_starter/option.rb', line 4

def switch_description
  @switch_description
end

Class Method Details

.simplified_switch_name(switch) ⇒ Object

Remove leading hyphens Convert remaining hyphens to underscores Undercase



25
26
27
# File 'lib/rspec_starter/option.rb', line 25

def self.simplified_switch_name(switch)
  switch.sub(/^-*/, "").sub("-", "_").underscore
end

Instance Method Details

#is_dsl_option?Boolean

Does this option apply to the DSL inside the RspecStarter.start block. If so, users can use it like this:

RspecStarter.start do
  task :foo, option_name_here: "some_value"
end

Returns:

  • (Boolean)


33
34
35
# File 'lib/rspec_starter/option.rb', line 33

def is_dsl_option?
  !name.nil?
end