Class: YardJunk::Janitor::YardOptions

Inherits:
Object
  • Object
show all
Defined in:
lib/yard-junk/janitor/yard_options.rb

Overview

Allows to properly parse ‘.yardopts` or other option file YARD supports and gracefully replace or remove some of options.

Defined Under Namespace

Classes: Internal

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeYardOptions

Returns a new instance of YardOptions.



10
11
12
13
14
15
16
# File 'lib/yard-junk/janitor/yard_options.rb', line 10

def initialize
  internal = Internal.new
  internal.parse_arguments
  @options = internal.option_args
  @files = internal.files
  @extra_files = internal.options.files
end

Instance Attribute Details

#extra_filesObject (readonly)

Returns the value of attribute extra_files.



8
9
10
# File 'lib/yard-junk/janitor/yard_options.rb', line 8

def extra_files
  @extra_files
end

#filesObject (readonly)

Returns the value of attribute files.



8
9
10
# File 'lib/yard-junk/janitor/yard_options.rb', line 8

def files
  @files
end

#optionsObject (readonly)

Returns the value of attribute options.



8
9
10
# File 'lib/yard-junk/janitor/yard_options.rb', line 8

def options
  @options
end

Instance Method Details

#remove_option(long, short = nil) ⇒ Object



24
25
26
27
28
29
30
31
32
33
# File 'lib/yard-junk/janitor/yard_options.rb', line 24

def remove_option(long, short = nil)
  [short, long].compact.each do |o|
    i = @options.index(o)
    next unless i

    @options.delete_at(i)
    @options.delete_at(i) unless @options[i].start_with?('-') # it was argument
  end
  self
end

#set_files(*files) ⇒ Object



18
19
20
21
22
# File 'lib/yard-junk/janitor/yard_options.rb', line 18

def set_files(*files)
  # TODO: REALLY fragile :(
  @files, @extra_files = files.partition { |f| f =~ /\.(rb|c|cxx|cpp|rake)/ }
  self
end

#to_aObject



35
36
37
38
# File 'lib/yard-junk/janitor/yard_options.rb', line 35

def to_a
  (@options + @files)
    .tap { |res| res.push('-', *@extra_files) unless @extra_files.empty? }
end