PageRenderTime 40ms CodeModel.GetById 29ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 1ms

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