Module: Aliyun::Log::Record

Extended by:
ActiveSupport::Concern
Includes:
ActiveModel::AttributeMethods, Field, Persistence, Scoping
Defined in:
lib/aliyun/log/record.rb,
lib/aliyun/log/record/field.rb,
lib/aliyun/log/record/scoping.rb,
lib/aliyun/log/record/relation.rb,
lib/aliyun/log/record/exception.rb,
lib/aliyun/log/record/persistence.rb,
lib/aliyun/log/record/type_casting.rb

Defined Under Namespace

Modules: ClassMethods, Field, Persistence, Scoping, TypeCasting Classes: ArgumentError, ParseStatementInvalid, ProjectNameError, Relation, UnknownAttributeError

Constant Summary

Constants included from Persistence

Persistence::RESERVED_FIELDS

Constants included from Field

Field::DEFAULT_INDEX_TOKEN, Field::PERMITTED_KEY_TYPES

Instance Attribute Summary

Attributes included from Field

#attributes

Instance Method Summary collapse

Methods included from Persistence

#dump_attributes, #dump_log_tags, #save, #save!

Methods included from Field

#attribute_names, #evaluate_default_value, #has_attribute?, #read_attribute, #set_created_at, #timestamps_enabled?, #write_attribute

Instance Method Details

#attribute_for_inspect(attr_name) ⇒ Object



103
104
105
106
107
108
109
110
111
112
113
# 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

#initialize(attrs = {}) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# 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

#inspectObject



91
92
93
94
95
96
97
98
99
100
101
# 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?Boolean

Returns:

  • (Boolean)


87
88
89
# File 'lib/aliyun/log/record.rb', line 87

def new_record?
  @new_record == true
end