Module: Compass::Configuration::Inheritance::ClassMethods

Defined in:
lib/compass/configuration/inheritance.rb

Defined Under Namespace

Classes: ArrayProxy

Instance Method Summary collapse

Instance Method Details

#chained_method(method) ⇒ Object



162
163
164
165
166
167
168
169
170
171
172
173
# File 'lib/compass/configuration/inheritance.rb', line 162

def chained_method(method)
  line = __LINE__ + 1
  class_eval %Q{
    alias_method :_chained_#{method}, method
    def #{method}(*args, &block)
      _chained_#{method}(*args, &block)
      if inherited_data
        inherited_data.#{method}(*args, &block)
      end
    end
  }, __FILE__, line
end

#inherited_accessor(*attributes) ⇒ Object



59
60
61
62
# File 'lib/compass/configuration/inheritance.rb', line 59

def inherited_accessor(*attributes)
  inherited_reader(*attributes)
  inherited_writer(*attributes)
end

#inherited_array(*attributes) ⇒ Object



112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/compass/configuration/inheritance.rb', line 112

def inherited_array(*attributes)
  options = attributes.last.is_a?(Hash) ? attributes.pop : {}
  inherited_reader(*attributes)
  inherited_writer(*attributes)
  attributes.each do |attr|
    line = __LINE__ + 1
    class_eval %Q{
      def #{attr}                                          # def sprite_load_paths
        ArrayProxy.new(self, #{attr.inspect})              #   ArrayProxy.new(self, :sprite_load_paths)
      end                                                  # end
      def #{attr}=(value)                                  # def sprite_load_paths=(value)
        @set_attributes ||= {}                             #   @set_attributes ||= {}
        @set_attributes[#{attr.inspect}] = true            #   @set_attributes[:sprite_load_paths] = true
        @#{attr} = Array(value)                            #   @sprite_load_paths = Array(value)
        @added_to_#{attr} = []                             #   @added_to_sprite_load_paths = []
        @removed_from_#{attr} = []                         #   @removed_from_sprite_load_paths = []
      end                                                  # end
      def read_inherited_#{attr}_array                     # def read_inherited_sprite_load_paths_array
        value = if inherited_data                          #   value = if inherited_data
          if #{!!options[:clobbers]} && #{attr}_set?
            Array(@#{attr})                                #     Array(@#{attr})
          else
            Array(@#{attr}) + inherited_data.read_inherited_#{attr}_array  #      inherited_data.read_inherited_sprite_load_paths_array + Array(@sprite_load_paths)
          end
        elsif #{attr}_set?                                 #   elsif sprite_load_paths_set?
          Array(@#{attr})                                  #     Array(@#{attr})
        else                                               #   else
          top_level.default_for(#{attr.inspect}) || []     #     top_level.default_for(:sprite_load_paths) || []
        end                                                #   end
        value -= Array(@removed_from_#{attr})              #   value -= Array(@removed_from_sprite_load_paths)
        Array(@added_to_#{attr}) + value                   #   Array(@added_to_sprite_load_paths) + value
      end                                                  # end
      def add_to_#{attr}(v)                                # def add_to_sprite_load_paths(v)
        if #{attr}_set?                                    #   if sprite_load_paths_set?
          raw_#{attr} << v                                 #     raw_sprite_load_paths << v
        else                                               #   else
          (@added_to_#{attr} ||= []) << v                  #     (@added_to_sprite_load_paths ||= []) << v
        end                                                #   end
      end                                                  # end
      def remove_from_#{attr}(v)                           # def remove_from_sprite_load_paths(v)
        if #{attr}_set?                                    #   if sprite_load_paths_set?
          raw_#{attr}.reject!{|e| e == v}                  #     raw_sprite_load_path.reject!{|e| e == v}s
        else                                               #   else
          (@removed_from_#{attr} ||= []) << v              #     (@removed_from_sprite_load_paths ||= []) << v
        end                                                #   end
      end                                                  # end
    }, __FILE__, line
  end
end

#inherited_reader(*attributes) ⇒ Object

Defines the default reader to be an inherited_reader that will look at the inherited_data for its value when not set. The inherited reader calls to a raw reader that acts like a normal attribute reader but prefixes the attribute name with “raw_”.



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/compass/configuration/inheritance.rb', line 42

def inherited_reader(*attributes)
  attributes.each do |attribute|
    line = __LINE__ + 1
    class_eval %Q{
      def raw_#{attribute}                         # def raw_css_dir
        @#{attribute}                              #   @css_dir
      end                                          # end
      def #{attribute}_without_default             # def css_dir_without_default
        read_without_default(#{attribute.inspect}) #  read_without_default(:css_dir)
      end                                          # end
      def #{attribute}                             # def css_dir
        read(#{attribute.inspect})                 #  read(:css_dir)
      end                                          # end
    }, __FILE__, line
  end
end

#inherited_writer(*attributes) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/compass/configuration/inheritance.rb', line 18

def inherited_writer(*attributes)
  attributes.each do |attribute|
    line = __LINE__ + 1
    class_eval %Q{
      def #{attribute}=(value)                        # def css_dir=(value)
        @set_attributes ||= {}                        #   @set_attributes ||= {}
        @set_attributes[#{attribute.inspect}] = true  #   @set_attributes[:css_dir] = true
        @#{attribute} = value                         #   @css_dir = value
      end                                             # end

      def unset_#{attribute}!                         # def unset_css_dir!
        unset!(#{attribute.inspect})                  #   unset!(:css_dir)
      end                                             # end

      def #{attribute}_set?                           # def css_dir_set?
        set?(#{attribute.inspect})                    #   set?(:css_dir)
      end                                             # end
    }, __FILE__, line
  end
end