Ruby
to_xml, with explicit and conditional removal of a :include
alias_method :old_to_xml, :to_xml
def to_xml(args={})
if args[:include]
if offline_at && offline_at <= Time.now
args[:include] -= [:data]
end
end
old_to_xml(args)
end
alias_method :old_to_xml, :to_xml
def to_xml(args={})
if args[:include]
if offline_at && offline_at <= Time.now
args[:include] -= [:data]
end
end
old_to_xml(args)
end
Refactorings
No refactoring yet !
January 14, 2009,
January 14, 2009 21:12,
permalink
def to_xml(options = {})
options[:include] = Array(options[:include])
options[:include].delete(:data) if offline_at && offline_at <= Time.now
super(options)
end
If offline_at is before now, explicitly remove :data from :includes passed to to_xml
So, if offline_at > Time.now, and args = { :include => :data}, old_to_xml will be called with { :include => [] }