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-2.4.4 lib/superstore/inspect.rb
superstore-2.4.3 lib/superstore/inspect.rb
superstore-2.4.2 lib/superstore/inspect.rb
superstore-2.4.1 lib/superstore/inspect.rb
superstore-2.4.0 lib/superstore/inspect.rb
superstore-2.3.0 lib/superstore/inspect.rb
superstore-2.2.0 lib/superstore/inspect.rb
superstore-2.1.3 lib/superstore/inspect.rb
superstore-2.1.2 lib/superstore/inspect.rb
superstore-2.1.1 lib/superstore/inspect.rb
superstore-2.1.0 lib/superstore/inspect.rb
superstore-2.0.1 lib/superstore/inspect.rb
superstore-2.0.0 lib/superstore/inspect.rb
superstore-1.2.0 lib/superstore/inspect.rb
superstore-1.1.4 lib/superstore/inspect.rb
superstore-1.1.3 lib/superstore/inspect.rb
superstore-1.1.2 lib/superstore/inspect.rb
superstore-1.1.1 lib/superstore/inspect.rb
superstore-1.1.0 lib/superstore/inspect.rb
superstore-1.0.12 lib/superstore/inspect.rb