Class: Filigree::Configuration::Option

Inherits:
Struct
  • Object
show all
Defined in:
lib/filigree/configuration.rb

Overview

This class represents an option that can appear in the configuration.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#defaultObject

Returns the value of attribute default



356
357
358
# File 'lib/filigree/configuration.rb', line 356

def default
  @default
end

#handlerObject

Returns the value of attribute handler



356
357
358
# File 'lib/filigree/configuration.rb', line 356

def handler
  @handler
end

#helpObject

Returns the value of attribute help



356
357
358
# File 'lib/filigree/configuration.rb', line 356

def help
  @help
end

#longObject

Returns the value of attribute long



356
357
358
# File 'lib/filigree/configuration.rb', line 356

def long
  @long
end

#shortObject

Returns the value of attribute short



356
357
358
# File 'lib/filigree/configuration.rb', line 356

def short
  @short
end

Class Method Details

.to_s(options, indent = 0) ⇒ String

Helper method used to print out information on a set of options.



398
399
400
401
402
403
404
405
406
407
408
409
# File 'lib/filigree/configuration.rb', line 398

def self.to_s(options, indent = 0)
  lines = []

  max_long  = options.lazy.map { |opt| opt.long.length }.max
  max_short = options.lazy.map(&:short).reject { |opt| opt.nil? }.map(&:length).max

  options.each do |opt|
    lines << opt.to_s(max_long, max_short, indent)
  end

  lines.join("\n")
end

Instance Method Details

#arityFixnum

Returns the number of arguments that this option takes.



362
363
364
365
366
367
# File 'lib/filigree/configuration.rb', line 362

def arity
  case self.handler
  when Array then self.handler.length
  when Proc  then self.handler.arity
  end
end

#to_s(max_long, max_short, indent = 0) ⇒ String

Print the option information out as a string.

Layout: | ||–‘long`,|| ||-`short`|| | |_||_||_||__||_|

indent    max_l+3  1   max_s+1   3


381
382
383
384
385
386
387
388
389
390
# File 'lib/filigree/configuration.rb', line 381

def to_s(max_long, max_short, indent = 0)
  segment_indent = indent + max_long + max_short + 8
  segmented_help = self.help.segment(segment_indent)

  if self.short
    sprintf "#{' ' * indent}%-#{max_long + 3}s %-#{max_short + 1}s   %s", "--#{self.long},", '-' + self.short, segmented_help
  else
    sprintf "#{' ' * indent}%-#{max_long + max_short + 5}s   %s", '--' + self.long, segmented_help
  end
end