Sha256: 39ac8d23e57d23abdc5521c6ec97978a8bbd3703be9ab9ea1da69554f827d093
Contents?: true
Size: 1.17 KB
Versions: 33
Compression:
Stored size: 1.17 KB
Contents
require 'awesome_print' module Cistern::Formatter::AwesomePrint def self.call(model) model.ai end end module AwesomePrint::Cistern def self.included(base) base.send :alias_method, :cast_without_cistern, :cast base.send :alias_method, :cast, :cast_with_cistern end def cast_with_cistern(object, type) cast = cast_without_cistern(object, type) if object.is_a?(Cistern::Model) cast = :cistern_model elsif object.is_a?(Cistern::Singular) cast = :cistern_model elsif object.is_a?(Cistern::Collection) cast = :cistern_collection end cast end # Format Cistern::Model #------------------------------------------------------------------------------ def awesome_cistern_model(object) data = object.attributes.keys.inject({}){|r,k| r.merge(k => object.send(k))} "#{object} " << awesome_hash(data) end # Format Cistern::Model #------------------------------------------------------------------------------ def awesome_cistern_collection(object) "#{object.class.name} " << awesome_hash(attributes: object.attributes, records: object.to_a) end end AwesomePrint::Formatter.send(:include, AwesomePrint::Cistern)
Version data entries
33 entries across 33 versions & 1 rubygems