Sha256: 52c11484b24414dc3845fc8c0c0a3a70a3dba895634b26b271bae47eed810fe4

Contents?: true

Size: 856 Bytes

Versions: 6

Compression:

Stored size: 856 Bytes

Contents

module Her
  module Model
    module Introspection
      # Inspect an element, returns it for introspection.
      #
      # @example
      #   class User
      #     include Her::Model
      #   end
      #
      #   @user = User.find(1)
      #   p @user # => #<User(/users/1) id=1 name="Tobias Fünke">
      def inspect # {{{
        "#<#{self.class}(#{self.class.build_request_path(@data)}) #{@data.inject([]) { |memo, item| key, value = item; memo << "#{key}=#{attribute_for_inspect(value)}"}.join(" ")}>"
      end # }}}

      private
      # @private
      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}")
        else
          value.inspect
        end
      end # }}}
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
her-0.2.6 lib/her/model/introspection.rb
her-0.2.5 lib/her/model/introspection.rb
her-0.2.4 lib/her/model/introspection.rb
her-0.2.3 lib/her/model/introspection.rb
her-0.2.2 lib/her/model/introspection.rb
her-0.2.1 lib/her/model/introspection.rb