Class: ThorEnhance::Autogenerate::Option
- Inherits:
-
Object
- Object
- ThorEnhance::Autogenerate::Option
- Defined in:
- lib/thor_enhance/autogenerate/option.rb
Constant Summary collapse
- TEMPLATE_ERB =
"#{File.dirname(__FILE__)}/templates/option.rb.erb"
- OPTION_TEMPLATE =
ERB.new(File.read(TEMPLATE_ERB))
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#option ⇒ Object
readonly
Returns the value of attribute option.
Instance Method Summary collapse
-
#initialize(name:, option:) ⇒ Option
constructor
A new instance of Option.
- #invocations ⇒ Object
- #readme_type ⇒ Object
- #template_text ⇒ Object
Constructor Details
#initialize(name:, option:) ⇒ Option
Returns a new instance of Option.
13 14 15 16 |
# File 'lib/thor_enhance/autogenerate/option.rb', line 13 def initialize(name:, option:) @name = name @option = option end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
11 12 13 |
# File 'lib/thor_enhance/autogenerate/option.rb', line 11 def name @name end |
#option ⇒ Object (readonly)
Returns the value of attribute option.
11 12 13 |
# File 'lib/thor_enhance/autogenerate/option.rb', line 11 def option @option end |
Instance Method Details
#invocations ⇒ Object
29 30 31 32 33 34 35 36 37 |
# File 'lib/thor_enhance/autogenerate/option.rb', line 29 def invocations base = [option.switch_name] + option.aliases if option.type == :boolean counter = option.switch_name.sub("--", "--no-") base << counter end base end |
#readme_type ⇒ Object
39 40 41 |
# File 'lib/thor_enhance/autogenerate/option.rb', line 39 def readme_type option.readme || ThorEnhance.configuration.autogenerated_config.readme_empty_group end |
#template_text ⇒ Object
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/thor_enhance/autogenerate/option.rb', line 18 def template_text text = [] text << "# What: #{option.description}" text << "# Type: #{option.type}" text << "# Required: #{option.required}" text << "# Allowed Inputs: #{option.enum}" if option.enum text << invocations.map { "#{_1}"}.join(" | ") text.join("\n") end |