Module: Document::Associations
- Included in:
- SampleManifest
- Defined in:
- app/models/document.rb
Instance Method Summary collapse
-
#has_uploaded_document(field, differentiator: field.to_s) ⇒ Object
Adds accessors for named fields and attaches documents to them.
Instance Method Details
#has_uploaded_document(field, differentiator: field.to_s) ⇒ Object
Adds accessors for named fields and attaches documents to them
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'app/models/document.rb', line 10 def has_uploaded_document(field, differentiator: field.to_s) # rubocop:todo Metrics/MethodLength # Options # differentiator - this is a string used to separate multiple documents related to your model # for example, you can have both a "generated" and an "uploaded" document in one Sample Manifest line = __LINE__ + 1 class_eval( " has_one( :#{field}_document, ->(){ where(documentable_extended: differentiator) }, class_name: \"Document\", as: :documentable, dependent: :destroy ) def #{field} self.#{field}_document end def #{field}=(file) create_#{field}_document(uploaded_data: file, documentable_extended: '#{differentiator}') unless file.blank? end ", __FILE__, line ) end |