Module: Ptf::FileSystem

Defined in:
lib/ptf/file_system.rb

Class Method Summary collapse

Class Method Details

.base_dirObject



19
20
21
# File 'lib/ptf/file_system.rb', line 19

def base_dir
  config[:base_dir]
end

.configObject



9
10
11
12
13
# File 'lib/ptf/file_system.rb', line 9

def config
  @config = Ptf::Config.get_config if @config.nil?

  @config
end

.data_dirObject



47
48
49
# File 'lib/ptf/file_system.rb', line 47

def data_dir
  File.join(base_dir, config[:task_data_dir])
end

.file_exist?(filepath) ⇒ Boolean

Returns:

  • (Boolean)


5
6
7
# File 'lib/ptf/file_system.rb', line 5

def file_exist?(filepath)
  File.file?(filepath)
end

.file_permissionObject



15
16
17
# File 'lib/ptf/file_system.rb', line 15

def file_permission
  @config[:file_permission]
end

.find_file(id, open = true) ⇒ Object

Raises:

  • (ArgumentError)


61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/ptf/file_system.rb', line 61

def find_file(id, open = true)
  raise ArgumentError, "No task with id #{id} exists." unless id_exist?(id)

  search_dir = (open ?  : )
  groups = Ptf::Group.all_groups

  groups.each do |g|
    dir = File.join(search_dir, g.name)
    possible_id_file = File.join(dir, id.to_s)

    if file_exist?(possible_id_file)
      return possible_id_file
    end
  end

  nil
end

.group_list_fileObject



31
32
33
# File 'lib/ptf/file_system.rb', line 31

def group_list_file
  File.join(base_dir, config[:group_list_file])
end

.id_counter_fileObject



23
24
25
# File 'lib/ptf/file_system.rb', line 23

def id_counter_file
  File.join(base_dir, config[:task_counter_file])
end

.id_counter_starting_contentObject



27
28
29
# File 'lib/ptf/file_system.rb', line 27

def id_counter_starting_content
  config[:id_counter_start]
end

.id_exist?(id) ⇒ Boolean

Returns:

  • (Boolean)


55
56
57
58
59
# File 'lib/ptf/file_system.rb', line 55

def id_exist?(id)
  next_id = File.read(id_counter_file).to_i

  (id < next_id && id > 0)
end

.metadata_closed_dirObject



43
44
45
# File 'lib/ptf/file_system.rb', line 43

def 
  File.join(, config[:completed_dir])
end

.metadata_dirObject



35
36
37
# File 'lib/ptf/file_system.rb', line 35

def 
  File.join(base_dir, config[:task_metadata_dir])
end

.metadata_open_dirObject



39
40
41
# File 'lib/ptf/file_system.rb', line 39

def 
  File.join(, config[:in_progress_dir])
end

.tmp_dirObject



51
52
53
# File 'lib/ptf/file_system.rb', line 51

def tmp_dir
  File.join(base_dir, config[:tmp_dir])
end