Stroy#105839906 more cleanup to remove legal_documents_versions + some code reading-refactorings

This commit is contained in:
Vladimir Krylov 2015-11-17 14:44:10 +02:00
parent c0960e9184
commit 3f17f728eb
4 changed files with 14 additions and 46 deletions

View file

@ -1,17 +1,19 @@
class LegalDocument < ActiveRecord::Base
extend VersionCreator
belongs_to :documentable, polymorphic: true
if ENV['legal_document_types'].present?
TYPES = ENV['legal_document_types'].split(',').map(&:strip)
else
TYPES = %w(pdf bdoc ddoc zip rar gz tar 7z odt doc docx)
TYPES = %w(pdf bdoc ddoc zip rar gz tar 7z odt doc docx).freeze
end
attr_accessor :body
before_save :save_to_filesystem
belongs_to :documentable, polymorphic: true
before_create :add_creator
before_save :save_to_filesystem
def save_to_filesystem
loop do
rand = SecureRandom.random_number.to_s.last(4)
@ -26,4 +28,9 @@ class LegalDocument < ActiveRecord::Base
File.open(path, 'wb') { |f| f.write(Base64.decode64(body)) } unless Rails.env.test?
self.path = path
end
def add_creator
self.creator_str = ::PaperTrail.whodunnit
true
end
end