module Sufia::UserLocalDirectoryBehavior

To enable local file ingest,

Public Instance Methods

directory_must_exist() click to toggle source

You can use this validator in your User model. Ensures that a string defining the path to the user's directory has been provided and corresponds to a real directory on the server. @example

validate :directory_must_exist
# File lib/sufia/models/user_local_directory_behavior.rb, line 12
def directory_must_exist
  return if directory.blank? || File.directory?(directory)
  errors.add(:directory, "must be an existing directory")
end
files() click to toggle source

List the contents of the user's directory on the server Indicates whether each item is a directory or not.

# File lib/sufia/models/user_local_directory_behavior.rb, line 19
def files
  return [] unless directory.present? && File.directory?(directory)
  Dir[File.join(directory, '*')].each_with_object([]) do |val, accum|
    accum << { name: File.basename(val), directory: File.directory?(val) }
  end
end