Files
nairobi/app/models/concerns/documentable.rb
Javi Martín 42d2e5b3ad Apply Rails/InverseOf rubocop rule
Not doing so has a few gotchas when working with relations, particularly
with records which are not stored in the database.

I'm excluding the related content file because it's got a very peculiar
relationship with itself: the `has_one :opposite_related_content` has no
inverse; the relation itself is its inverse. It's a false positive since
the inverse condition is true:

```
content.opposite_related_content.opposite_related_content.object_id ==
  content.object_id
```
2019-10-25 19:29:12 +02:00

23 lines
566 B
Ruby

module Documentable
extend ActiveSupport::Concern
included do
has_many :documents, as: :documentable, inverse_of: :documentable, dependent: :destroy
accepts_nested_attributes_for :documents, allow_destroy: true
end
module ClassMethods
def max_documents_allowed
Setting["uploads.documents.max_amount"].to_i
end
def max_file_size
Setting["uploads.documents.max_size"].to_i.megabytes
end
def accepted_content_types
Setting["uploads.documents.content_types"]&.split(" ") || ["application/pdf"]
end
end
end