Class: RspecStarter::Option
- Inherits:
-
Object
- Object
- RspecStarter::Option
- 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
-
#default ⇒ Object
readonly
Returns the value of attribute default.
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#name ⇒ Object
Returns the value of attribute name.
-
#owner ⇒ Object
readonly
Returns the value of attribute owner.
-
#switch ⇒ Object
readonly
Returns the value of attribute switch.
-
#switch_description ⇒ Object
readonly
Returns the value of attribute switch_description.
Class Method Summary collapse
-
.simplified_switch_name(switch) ⇒ Object
Remove leading hyphens Convert remaining hyphens to underscores Undercase.
Instance Method Summary collapse
-
#initialize(name:, default:, owner:, switch:, description: "", switch_description: "") ⇒ Option
constructor
A new instance of Option.
-
#is_dsl_option? ⇒ Boolean
Does this option apply to the DSL inside the RspecStarter.start block.
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
#default ⇒ Object (readonly)
Returns the value of attribute default.
4 5 6 |
# File 'lib/rspec_starter/option.rb', line 4 def default @default end |
#description ⇒ Object (readonly)
Returns the value of attribute description.
4 5 6 |
# File 'lib/rspec_starter/option.rb', line 4 def description @description end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
4 5 6 |
# File 'lib/rspec_starter/option.rb', line 4 def key @key end |
#name ⇒ Object
Returns the value of attribute name.
4 5 6 |
# File 'lib/rspec_starter/option.rb', line 4 def name @name end |
#owner ⇒ Object (readonly)
Returns the value of attribute owner.
4 5 6 |
# File 'lib/rspec_starter/option.rb', line 4 def owner @owner end |
#switch ⇒ Object (readonly)
Returns the value of attribute switch.
4 5 6 |
# File 'lib/rspec_starter/option.rb', line 4 def switch @switch end |
#switch_description ⇒ Object (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
33 34 35 |
# File 'lib/rspec_starter/option.rb', line 33 def is_dsl_option? !name.nil? end |