Class: ThorEnhance::Autogenerate::Option

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#nameObject (readonly)

Returns the value of attribute name.



11
12
13
# File 'lib/thor_enhance/autogenerate/option.rb', line 11

def name
  @name
end

#optionObject (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

#invocationsObject



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_typeObject



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_textObject



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