Class: SSC::DirectoryManager::FileListFile

Inherits:
LocalStorageFile show all
Defined in:
lib/directory_manager.rb

Instance Method Summary collapse

Methods inherited from LocalStorageFile

#[], #empty_list?, #push, #read, #save, #valid?

Constructor Details

#initialize(path = nil) ⇒ FileListFile

Returns a new instance of FileListFile.



74
75
76
# File 'lib/directory_manager.rb', line 74

def initialize(path= nil)
  super("files/.file_list", path)
end

Instance Method Details

#initiate_file(path, options) ⇒ Object



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/directory_manager.rb', line 89

def initiate_file(path, options)
  raise "Unknown file #{path}" unless File.exists?(path)
  file_path, file_name= File.split(path)
  file_path ||= options[:path]
  destination_path= File.join(File.split(@location)[0], file_name)
  FileUtils.cp(path, destination_path)
  if options[:id]
    push("list", {file_name => {
      "id" => options[:id],
      "path" => file_path }})
  else
    file_params= options.slice(:permissions, :group, :owner).merge(:path => file_path)
    push("add", {file_name => file_params})
  end
  destination_path
end

#is_uploaded?(file_name) ⇒ Boolean

Returns:

  • (Boolean)


106
107
108
109
110
# File 'lib/directory_manager.rb', line 106

def is_uploaded?(file_name)
  read
  list= @parsed_file["list"].select{|i| i.keys[0] == file_name}
  list[0][file_name]["id"] if list.length > 0 
end

#pop(section) ⇒ Object



78
79
80
81
82
83
84
85
86
87
# File 'lib/directory_manager.rb', line 78

def pop(section)
  file_hash= super(section)
  if file_hash
    file_name= file_hash.keys[0]
    file_hash= file_hash[file_name]
    { :name      => file_name,
      :full_path => File.join(file_hash["path"]),
      :params    => file_hash.slice("owner", "group", "permissions")}
  end
end