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

Version Path
cistern-0.12.3 lib/cistern/formatter/awesome_print.rb
cistern-2.2.3 lib/cistern/formatter/awesome_print.rb
cistern-2.2.1 lib/cistern/formatter/awesome_print.rb
cistern-2.1.0 lib/cistern/formatter/awesome_print.rb
cistern-2.0.5 lib/cistern/formatter/awesome_print.rb
cistern-2.0.4 lib/cistern/formatter/awesome_print.rb
cistern-0.12.2 lib/cistern/formatter/awesome_print.rb
cistern-0.12.1 lib/cistern/formatter/awesome_print.rb
cistern-2.0.3 lib/cistern/formatter/awesome_print.rb
cistern-2.0.2 lib/cistern/formatter/awesome_print.rb
cistern-0.11.3 lib/cistern/formatter/awesome_print.rb
cistern-2.0.1 lib/cistern/formatter/awesome_print.rb
cistern-1.0.1.pre6 lib/cistern/formatter/awesome_print.rb
cistern-1.0.1.pre5 lib/cistern/formatter/awesome_print.rb
cistern-1.0.1.pre4 lib/cistern/formatter/awesome_print.rb
cistern-1.0.1.pre3 lib/cistern/formatter/awesome_print.rb
cistern-1.0.1.pre2 lib/cistern/formatter/awesome_print.rb
cistern-0.11.2 lib/cistern/formatter/awesome_print.rb
cistern-1.0.1.pre1 lib/cistern/formatter/awesome_print.rb
cistern-1.0.0.pre lib/cistern/formatter/awesome_print.rb