Module: RailsExtend::ActiveStorage::BlobPrepend

Defined in:
lib/rails_extend/active_storage/blob_prepend.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.prepended(klass) ⇒ Object



6
7
8
9
10
11
12
13
14
15
# File 'lib/rails_extend/active_storage/blob_prepend.rb', line 6

def self.prepended(klass)
  klass.attribute :key, :string, null: false, index: { unique: true }
  klass.attribute :filename, :string, null: false
  klass.attribute :content_type, :string
  klass.attribute :metadata, :json
  klass.attribute :byte_size, :integer, null: false
  klass.attribute :checksum, :string
  klass.attribute :service_name, :string, null: false
  klass.attribute :created_at, :datetime, null: false
end

Instance Method Details

#data_url ⇒ Object



17
18
19
20
# File 'lib/rails_extend/active_storage/blob_prepend.rb', line 17

def data_url
  return @data_url if defined? @data_url
  @data_url = "data:#{content_type};base64,#{Base64.encode64(download)}"
end

#duration ⇒ Object



22
23
24
# File 'lib/rails_extend/active_storage/blob_prepend.rb', line 22

def duration
  ([:duration] || 0).to_f
end

#duration_str ⇒ Object



26
27
28
29
# File 'lib/rails_extend/active_storage/blob_prepend.rb', line 26

def duration_str
  rh = TimeHelper.exact_distance_time(duration)
  "#{rh[:minute]}:#{rh[:second].to_s.rjust(2, '0')}"
end

#identify_later ⇒ Object



31
32
33
# File 'lib/rails_extend/active_storage/blob_prepend.rb', line 31

def identify_later
  ActiveStorage::IdentifyJob.perform_later(self)
end