module Her::Model::Introspection

Public Instance Methods

inspect() click to toggle source

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">
# File lib/her/model/introspection.rb, line 14
def inspect
  resource_path = begin
    request_path
  rescue Her::Errors::PathError => e
    "<unknown path, missing `#{e.missing_parameter}`>"
  end

  "#<#{self.class}(#{resource_path}) #{attributes.keys.map { |k| "#{k}=#{attribute_for_inspect(send(k))}" }.join(" ")}>"
end

Private Instance Methods

attribute_for_inspect(value) click to toggle source
# File lib/her/model/introspection.rb, line 25
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)
    %Q("#{value}")
  else
    value.inspect
  end
end