Sha256: f26ce008b92c298c6dfca8309ceb6f2cfcabfaf18e56547945b23f73572514e9

Contents?: true

Size: 823 Bytes

Versions: 1

Compression:

Stored size: 823 Bytes

Contents

module Recliner
  module PrettyInspect
    extend ActiveSupport::Concern
  
    module ClassMethods
      # Returns a string like 'Post(title:String, body:String)'
      def inspect
        if self == Recliner::Document
          super
        else
          attr_list = model_properties.map { |name, property| "#{name}: #{property.type}" } * ', '
          "#{super}(#{attr_list})"
        end
      end
    end
  
    # Returns the contents of the document as a nicely formatted string.
    def inspect
      "#<#{self.class.name} #{attributes_for_inspect}>"
    end
  
  private
    def attributes_for_inspect
      attrs = self.class.model_properties.map { |name, property| "#{name}: #{send(name).inspect}" }
      attrs.unshift "rev: #{rev}" if rev
      attrs.unshift "id: #{id}"
      attrs * ', '
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
recliner-0.0.1 lib/recliner/pretty_inspect.rb