Class: Sass::Deprecation

Inherits:
Object
  • Object
show all
Defined in:
lib/sass/deprecation.rb

Overview

A deprecation warning that should only be printed once for a given line in a given file.

A global Deprecation instance should be created for each type of deprecation warning, and warn should be called each time a warning is needed.

Constant Summary collapse

@@allow_double_warnings =
false

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDeprecation

Returns a new instance of Deprecation.



20
21
22
23
# File 'lib/sass/deprecation.rb', line 20

def initialize
  # A set of filename, line pairs for which warnings have been emitted.
  @seen = Set.new
end

Class Method Details

.allow_double_warnings

Runs a block in which double deprecation warnings for the same location are allowed.



12
13
14
15
16
17
18
# File 'lib/sass/deprecation.rb', line 12

def self.allow_double_warnings
  old_allow_double_warnings = @@allow_double_warnings
  @@allow_double_warnings = true
  yield
ensure
  @@allow_double_warnings = old_allow_double_warnings
end

Instance Method Details

#warn(filename, line, message) #warn(filename, line, column, message)

Prints message as a deprecation warning associated with filename, line, and optionally column.

This ensures that only one message will be printed for each line of a given file.

Overloads:

  • #warn(filename, line, message)

    Parameters:

    • filename (String, nil)
    • line (Number)
    • message (String)
  • #warn(filename, line, column, message)

    Parameters:

    • filename (String, nil)
    • line (Number)
    • column (Number)
    • message (String)


40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/sass/deprecation.rb', line 40

def warn(filename, line, column_or_message, message = nil)
  return if !@@allow_double_warnings && @seen.add?([filename, line]).nil?
  if message
    column = column_or_message
  else
    message = column_or_message
  end

  location = "line #{line}"
  location << ", column #{column}" if column
  location << " of #{filename}" if filename

  Sass::Util.sass_warn("DEPRECATION WARNING on #{location}:\n#{message}")
end