Sha256: e0222ca5de0aa451773679825aba71592e6920e5a6257b6a8b53510639a77429

Contents?: true

Size: 605 Bytes

Versions: 31

Compression:

Stored size: 605 Bytes

Contents

module Superstore
  module Inspect
    def inspect
      inspection = ["#{self.class.primary_key}: #{id.inspect}"]

      @attributes.each do |attribute, value|
        if value.present?
          inspection << "#{attribute}: #{attribute_for_inspect(value)}"
        end
      end

      "#<#{self.class} #{inspection * ', '}>"
    end

    def attribute_for_inspect(value)
      if value.is_a?(String) && value.length > 50
        "#{value[0..50]}...".inspect
      elsif value.is_a?(Date) || value.is_a?(Time)
        %("#{value.to_s(:db)}")
      else
        value.inspect
      end
    end
  end
end

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
superstore-1.0.11 lib/superstore/inspect.rb
superstore-1.0.10 lib/superstore/inspect.rb
superstore-1.0.9 lib/superstore/inspect.rb
superstore-1.0.8 lib/superstore/inspect.rb
superstore-1.0.7 lib/superstore/inspect.rb
superstore-1.0.6 lib/superstore/inspect.rb
superstore-1.0.5 lib/superstore/inspect.rb
superstore-1.0.4 lib/superstore/inspect.rb
superstore-1.0.3 lib/superstore/inspect.rb
superstore-1.0.2 lib/superstore/inspect.rb
superstore-1.0.0 lib/superstore/inspect.rb