Created
April 19, 2011 03:38
-
-
Save timothy1ee/926776 to your computer and use it in GitHub Desktop.
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
# Returns a hash based representation of any data object given ejs template block | |
# object_to_hash(@user) { attribute :full_name } => { ... } | |
# object_to_hash(@user, :source => "...") { attribute :full_name } => { ... } | |
def object_to_hash(object, options={}, &block) | |
return object unless is_record?(object) || object.respond_to?(:each) | |
object = { data_object(object) => data_name(object) } if object.is_a?(Hash) && object.keys.first.is_a?(Symbol) | |
engine_options = { :format => "hash", :root => (options[:root] || false) } | |
Rabl::Engine.new(options[:source], engine_options).render(@_scope, :object => object, &block) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment