We were very inconsistent regarding these rules. Personally I prefer no empty lines around blocks, clases, etc... as recommended by the Ruby style guide [1], and they're the default values in rubocop, so those are the settings I'm applying. The exception is the `private` access modifier, since we were leaving empty lines around it most of the time. That's the default rubocop rule as well. Personally I don't have a strong preference about this one. [1] https://rubystyle.guide/#empty-lines-around-bodies
36 lines
1.2 KiB
Ruby
36 lines
1.2 KiB
Ruby
module DocumentablesHelper
|
|
def documentable_class(documentable)
|
|
documentable.class.name.parameterize(separator: "_")
|
|
end
|
|
|
|
def max_documents_allowed(documentable)
|
|
documentable.class.max_documents_allowed
|
|
end
|
|
|
|
def max_file_size(documentable_class)
|
|
bytes_to_mega(documentable_class.max_file_size)
|
|
end
|
|
|
|
def accepted_content_types(documentable_class)
|
|
documentable_class.accepted_content_types
|
|
end
|
|
|
|
def accepted_content_types_extensions(documentable_class)
|
|
Setting.accepted_content_types_for("documents").map { |content_type| ".#{content_type}" }.join(",")
|
|
end
|
|
|
|
def documentable_humanized_accepted_content_types(documentable_class)
|
|
Setting.accepted_content_types_for("documents").join(", ")
|
|
end
|
|
|
|
def documentables_note(documentable)
|
|
t "documents.form.note", max_documents_allowed: max_documents_allowed(documentable),
|
|
accepted_content_types: documentable_humanized_accepted_content_types(documentable.class),
|
|
max_file_size: max_file_size(documentable.class)
|
|
end
|
|
|
|
def max_documents_allowed?(documentable)
|
|
documentable.documents.count >= documentable.class.max_documents_allowed
|
|
end
|
|
end
|