Class: Compass::Configuration::Inheritance::ClassMethods::ArrayProxy

Inherits:
Object
  • Object
show all
Defined in:
lib/compass/configuration/inheritance.rb

Instance Method Summary collapse

Constructor Details

#initialize(data, attr) ⇒ ArrayProxy

Returns a new instance of ArrayProxy.



65
66
67
# File 'lib/compass/configuration/inheritance.rb', line 65

def initialize(data, attr)
  @data, @attr = data, attr
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *args, &block) ⇒ Object



102
103
104
105
106
107
108
109
# File 'lib/compass/configuration/inheritance.rb', line 102

def method_missing(m, *args, &block)
  a = to_ary
  if a.respond_to?(m)
    a.send(m,*args, &block)
  else
    super
  end
end

Instance Method Details

#<<(v) ⇒ Object



74
75
76
# File 'lib/compass/configuration/inheritance.rb', line 74

def <<(v)
  @data.send(:"add_to_#{@attr}", v)
end

#>>(v) ⇒ Object



77
78
79
# File 'lib/compass/configuration/inheritance.rb', line 77

def >>(v)
  @data.send(:"remove_from_#{@attr}", v)
end

#serialize_to_config(prop) ⇒ Object



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/compass/configuration/inheritance.rb', line 80

def serialize_to_config(prop)
  if v = @data.raw(prop)
    "#{prop} = #{v.inspect}"
  else
    s = ""
    if added = @data.instance_variable_get("@added_to_#{@attr}")
      added.each do |a|
        s << "#{prop} << #{a.inspect}\n"
      end
    end
    if removed = @data.instance_variable_get("@removed_from_#{@attr}")
      removed.each do |r|
        s << "#{prop} >> #{r.inspect}\n"
      end
    end
    if s[-1..-1] == "\n"
      s[0..-2]
    else
      s
    end
  end
end

#to_aObject



71
72
73
# File 'lib/compass/configuration/inheritance.rb', line 71

def to_a
  to_ary
end

#to_aryObject



68
69
70
# File 'lib/compass/configuration/inheritance.rb', line 68

def to_ary
  @data.send(:"read_inherited_#{@attr}_array")
end