/scalate-jruby/src/main/resources/haml-3.0.25/lib/sass/selector/abstract_sequence.rb

http://github.com/scalate/scalate · Ruby · 62 lines · 23 code · 5 blank · 34 comment · 4 complexity · ec02241180e22b1a47b4c0a4ced30f3a MD5 · raw file

  1. module Sass
  2. module Selector
  3. # The abstract parent class of the various selector sequence classes.
  4. #
  5. # All subclasses should implement a `members` method
  6. # that returns an array of object that respond to `#line=` and `#filename=`.
  7. class AbstractSequence
  8. # The line of the Sass template on which this selector was declared.
  9. #
  10. # @return [Fixnum]
  11. attr_reader :line
  12. # The name of the file in which this selector was declared.
  13. #
  14. # @return [String, nil]
  15. attr_reader :filename
  16. # Sets the line of the Sass template on which this selector was declared.
  17. # This also sets the line for all child selectors.
  18. #
  19. # @param line [Fixnum]
  20. # @return [Fixnum]
  21. def line=(line)
  22. members.each {|m| m.line = line}
  23. @line = line
  24. end
  25. # Sets the name of the file in which this selector was declared,
  26. # or `nil` if it was not declared in a file (e.g. on stdin).
  27. # This also sets the filename for all child selectors.
  28. #
  29. # @param filename [String, nil]
  30. # @return [String, nil]
  31. def filename=(filename)
  32. members.each {|m| m.filename = filename}
  33. @filename = filename
  34. end
  35. # Returns a hash code for this sequence.
  36. #
  37. # Subclasses should define `#_hash` rather than overriding this method,
  38. # which automatically handles memoizing the result.
  39. #
  40. # @return [Fixnum]
  41. def hash
  42. @_hash ||= _hash
  43. end
  44. # Checks equality between this and another object.
  45. #
  46. # Subclasses should define `#_eql?` rather than overriding this method,
  47. # which handles checking class equality and hash equality.
  48. #
  49. # @param other [Object] The object to test equality against
  50. # @return [Boolean] Whether or not this is equal to `other`
  51. def eql?(other)
  52. other.class == self.class && other.hash == self.hash && _eql?(other)
  53. end
  54. alias_method :==, :eql?
  55. end
  56. end
  57. end