class JsDuck::Warning::Basic

A basic warning type.

Public Class Methods

new(type, msg) click to toggle source

Creates a simple warning with a message text. The warning is disabled by default.

# File lib/jsduck/warning/basic.rb, line 11
def initialize(type, msg)
  @type = type
  @msg = msg

  @rules = []
  # disable by default
  set(false)
end

Public Instance Methods

doc() click to toggle source

Documentation for the warning.

# File lib/jsduck/warning/basic.rb, line 50
def doc
  " #{@rules[0][:enabled] ? '+' : '-'}#{@type} - #{@msg}"
end
enabled?(filename="", params=[]) click to toggle source

True when warning is enabled for the given filename. (The params parameter is ignored).

# File lib/jsduck/warning/basic.rb, line 44
def enabled?(filename="", params=[])
  # Find the most recently added rule that has an effect to our current item
  @rules.find {|r| r[:path_re].nil? || r[:path_re] =~ filename }[:enabled]
end
set(enabled, path_pattern=nil, params=[]) click to toggle source

Enables or disables the warning. Optionally enables/disables it for files matching a path_pattern. params array is not used for the basic warning type.

# File lib/jsduck/warning/basic.rb, line 23
def set(enabled, path_pattern=nil, params=[])
  if path_pattern
    # Prepend to the front of array, so we can use #find to
    # search for the latest rule.
    @rules.unshift({
      :enabled => enabled,
      :path_re => Regexp.new(Regexp.escape(path_pattern))
    })
  else
    # When no path specified, the warning is turned on/off
    # globally, so we can discard all the existing rules and
    # start over with just one.
    @rules = [{
      :enabled => enabled,
      :path_re => nil
    }]
  end
end