This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'delegate' | |
# An abstract decorator useful for decorating Active Record objects. | |
class ActiveRecordDecorator < SimpleDelegator | |
# A proxy for the decorator class to allow the delegation of certain class | |
# methods to the decorated object's class. | |
class ClassProxy < SimpleDelegator | |
def initialize(decorator_class, decorated_class) | |
super decorator_class | |
self.decorated_class = decorated_class |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# (v.respond_to?(:empty?) ? v.empty? : !v) is basically rails' .blank? in plain ruby | |
class Hash | |
def delete_blank | |
delete_if do |k, v| | |
(v.respond_to?(:empty?) ? v.empty? : !v) or v.instance_of?(Hash) && v.delete_blank.empty? | |
end | |
end | |
end |