Module: Aliyun::Log::Record::Persistence

Extended by:
ActiveSupport::Concern
Included in:
Aliyun::Log::Record
Defined in:
lib/aliyun/log/record/persistence.rb

Defined Under Namespace

Modules: ClassMethods

Constant Summary collapse

RESERVED_FIELDS =
%i[
  __time__
  __topic__
  __source__
  __partition_time__
  __extract_others__
].freeze

Instance Method Summary collapse

Instance Method Details

#dump_attributesObject



150
151
152
153
154
155
156
157
158
159
160
# File 'lib/aliyun/log/record/persistence.rb', line 150

def dump_attributes
  attributes.dup.tap do |tap|
    tap.each do |k, v|
      if self.class.attributes[k][:log_tag] || RESERVED_FIELDS.include?(k)
        tap.delete(k)
      else
        tap[k] = TypeCasting.dump_field(v, self.class.attributes[k])
      end
    end
  end
end

#dump_log_tagsObject



142
143
144
145
146
147
148
# File 'lib/aliyun/log/record/persistence.rb', line 142

def dump_log_tags
  log_tags = {}
  self.class.tag_attributes.map do |key, options|
    log_tags[key] = TypeCasting.dump_field(attributes[key], options)
  end
  log_tags.compact
end

#save(force = false) ⇒ Object



162
163
164
165
166
167
168
169
170
171
172
173
# File 'lib/aliyun/log/record/persistence.rb', line 162

def save(force = false)
  self.class.auto_load_schema
  run_callbacks(:create) do
    run_callbacks(:save) do
      force && validate!
      return false unless valid?
      saved = put_logs
      @new_record = false if saved
      saved
    end
  end
end

#save!Object



175
176
177
# File 'lib/aliyun/log/record/persistence.rb', line 175

def save!
  save(true)
end