app/models/directory.rb
def _validate_name
    if root?
      # Root nodes get a pass as long as name is empty string.
      # The name has no actual meaning to the user.
      if name != ''
        errors.add(:name, 'value must be empty for root directory')
      end
      return
    end
    # Basic checks:
    #   1. Non-root nodes have to pass the name regex
    #   2. Name isn't too damn long
    # If either check fails, then we can stop further checking
    max_directory_name_length = Settings[:app][:max_directory_name_length]
    if name.length > max_directory_name_length
      errors.add(:name, 'value exceeds maximum allowed length')
      return
    end
    valid_directory_name_regex = /#{Settings[:app][:valid_directory_name_regex]}/
    unless valid_directory_name_regex =~ name
      # It's okay to be vague
      errors.add(:name, 'value must be a valid directory name')
      return
    end
    # Make sure my siblings don't have the same name as me (CASE-INSENSITIVE)
    # Also, if we have a parent related error, we risk letting out info about another
    # user if we check a sibling name
    if errors.messages[:parent].blank?
      sibling_names = siblings.pluck(:name)
      if sibling_names.any?{ |s| s.casecmp(name) == 0 }
        errors.add(:name, 'already have a sibling with the same value')
      end
    end
  end
# A directory can contains other directories as well as files
# Deleting is recursive
A directory can contains other directories as well as files
Deleting is recursive
A directory can contains other directories as well as files Deleting is recursive
def _validate_name
    if root?
      if name != ''
        errors.add(:name, 'value must be empty for root directory')
      end
      return
    end
    max_directory_name_length = Settings[:app][:max_directory_name_length]
    if name.length > max_directory_name_length
      errors.add(:name, 'value exceeds maximum allowed length')
      return
    end
    valid_directory_name_regex = /#{Settings[:app][:valid_directory_name_regex]}/
    unless valid_directory_name_regex =~ name
      errors.add(:name, 'value must be a valid directory name')
      return
    end
    if errors.messages[:parent].blank?
      sibling_names = siblings.pluck(:name)
      if sibling_names.any?{ |s| s.casecmp(name) == 0 }
        errors.add(:name, 'already have a sibling with the same value')
      end
    end
  end
def _validate_name if root? if name != '' errors . add ( :name , 'value must be empty for root directory' ) end return end max_directory_name_length = Settings [ :app ] [ :max_directory_name_length ] if name . length > max_directory_name_length errors . add ( :name , 'value exceeds maximum allowed length' ) return end valid_directory_name_regex = / #{ Settings [ :app ] [ :valid_directory_name_regex ] } / unless valid_directory_name_regex =~ name errors . add ( :name , 'value must be a valid directory name' ) return end if errors . messages [ :parent ] . blank? sibling_names = siblings . pluck ( :name ) if sibling_names . any? { | s | s . casecmp ( name ) == 0 } errors . add ( :name , 'already have a sibling with the same value' ) end end end
A directory can contains other directories as well as files
Deleting is recursive
A directory can contains other directories as well as files Deleting is recursive
# Root nodes get a pass as long as name is empty string. # The name has no actual meaning to the user. # Basic checks: #   1. Non-root nodes have to pass the name regex #   2. Name isn't too damn long # If either check fails, then we can stop further checking # It's okay to be vague # Make sure my siblings don't have the same name as me (CASE-INSENSITIVE) # Also, if we have a parent related error, we risk letting out info about another # user if we check a sibling name