class Carraway::File
Attributes
category[RW]
created[R]
ext[R]
file[R]
labels[RW]
published[R]
title[RW]
uid[R]
Public Class Methods
new(title:, file: nil, uid: nil, ext: 'pdf', created: Time.now.to_i, labels: nil, published: nil, category: nil)
click to toggle source
# File lib/carraway/file.rb, line 9 def initialize(title:, file: nil, uid: nil, ext: 'pdf', created: Time.now.to_i, labels: nil, published: nil, category: nil) @title = title @file = file @uid = uid || generate_uid @ext = file && file[:filename]&.split('.')&.last || ext @created = created @labels = labels @published = published || created @category = category || Category.all.first # FIXME validation end
Public Instance Methods
path()
click to toggle source
# File lib/carraway/file.rb, line 27 def path # Seems prefix does not have to required parameter [Config.file_backend['prefix'], '/', @uid, ".#{@ext}"].join end
to_h()
click to toggle source
# File lib/carraway/file.rb, line 32 def to_h { uid: @uid, title: @title, path: path, labels: @labels, record_type: 'file', created: @created.to_i, published: @published && @published.to_i, category: @category.key, } end
Private Instance Methods
generate_uid()
click to toggle source
FIXME duplicate impl on Post
# File lib/carraway/file.rb, line 48 def generate_uid [Time.now.strftime('%Y%m%d%H%M%S'), "%05d" % rand(10000)].join end