module Aliyun::Log::Record
Public Class Methods
new(attrs = {})
click to toggle source
# File lib/aliyun/log/record.rb, line 62 def initialize(attrs = {}) run_callbacks :initialize do @new_record = true @attributes ||= {} attrs_with_defaults = self.class.attributes.each_with_object({}) do |(attribute, options), res| res[attribute] = if attrs.key?(attribute) attrs[attribute] elsif options.key?(:default) evaluate_default_value(options[:default]) end end attrs_virtual = attrs.slice(*(attrs.keys - self.class.attributes.keys)) attrs_with_defaults.merge(attrs_virtual).each do |key, value| if respond_to?("#{key}=") send("#{key}=", value) else raise UnknownAttributeError, "unknown attribute '#{key}' for #{@record.class}." end end end end
Public Instance Methods
attribute_for_inspect(attr_name)
click to toggle source
# File lib/aliyun/log/record.rb, line 103 def attribute_for_inspect(attr_name) value = read_attribute(attr_name) 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
inspect()
click to toggle source
# File lib/aliyun/log/record.rb, line 91 def inspect inspection = if defined?(@attributes) && @attributes self.class.attributes.keys.collect do |name| "#{name}: #{attribute_for_inspect(name)}" if has_attribute?(name) end.compact.join(', ') else 'not initialized' end "#<#{self.class} #{inspection}>" end
new_record?()
click to toggle source
# File lib/aliyun/log/record.rb, line 87 def new_record? @new_record == true end