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

Instance Method Summary collapse

Instance Method Details

#dump_attributesObject



126
127
128
129
130
131
132
# File 'lib/aliyun/log/record/persistence.rb', line 126

def dump_attributes
  attributes.dup.tap do |tap|
    tap.each do |k, v|
      tap[k] = TypeCasting.dump_field(v, self.class.attributes[k])
    end
  end
end

#saveObject



134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# File 'lib/aliyun/log/record/persistence.rb', line 134

def save
  self.class.auto_load_schema
  run_callbacks(:create) do
    run_callbacks(:save) do
      if valid?
        res = Log.record_connection.put_log(
          self.class.project_name,
          self.class.logstore_name,
          dump_attributes
        )
        res.code == 200
      else
        false
      end
    end
  end
end

#save_arrayObject



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

def save_array
  run_callbacks(:create) do
    run_callbacks(:save) do
      validate! && dump_attributes
    end
  end
end