9d4b720deb717771cd0116d21f7a36cd

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 => [] }

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 !

A8d3f35baafdaea851914b17dae9e1fc

Adam

January 14, 2009, January 14, 2009 21:12, permalink

1 rating. Login to rate!
def to_xml(options = {})
  options[:include] = Array(options[:include])
  options[:include].delete(:data) if offline_at && offline_at <= Time.now
  
  super(options)
end

Your refactoring





Format Copy from initial code

or Cancel