blob: 9ab07707a000376c1ba825f300795d785fd13057 (
plain) (
tree)
|
|
module ActiveRelation
class Rename < Compound
attr_reader :attribute, :pseudonym
def initialize(relation, pseudonyms)
@attribute, @pseudonym = pseudonyms.shift
@relation = pseudonyms.empty?? relation : Rename.new(relation, pseudonyms)
end
def ==(other)
self.class == other.class and
relation == other.relation and
attribute == other.attribute and
pseudonym == other.pseudonym
end
def attributes
relation.attributes.collect(&method(:christen))
end
private
def christen(attribute)
(attribute =~ self.attribute ? attribute.as(pseudonym) : attribute).bind(self) rescue nil
end
end
end
|