Class: GTDFileSystem

Inherits:
GTDSystem show all
Defined in:
lib/persistence.rb

Constant Summary

Constants included from Status

Status::ACTIVE_STATES, Status::INACTIVE_STATES, Status::STATUS_ORDER, Status::STATUS_SYMBOLS, Status::SYMBOLS_STATUS

Instance Attribute Summary

Attributes inherited from GTDSystem

#actions, #contexts, #projects

Instance Method Summary collapse

Methods inherited from GTDSystem

#active_actions, #do_process, #empty_inbox, #inactive_actions, #process, #projects_to_review, #set_to_done, #unprocess, #unprocess_active_actions, #unprocess_all_actions

Methods included from Status

#active, #directory_name, #inactive, #index, #symbol, #with_status

Constructor Details

#initialize(base_dir) ⇒ GTDFileSystem

Returns a new instance of GTDFileSystem.



20
21
22
23
# File 'lib/persistence.rb', line 20

def initialize(base_dir)
  @base_dir = base_dir
  @inbox = InboxFromFile.new "#{@base_dir}/@Inbox/Inbox.txt"
end

Instance Method Details

#done_actionsObject



87
88
89
# File 'lib/persistence.rb', line 87

def done_actions
  super + read_actions_in_done_folder
end

#parse_action_filesObject



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/persistence.rb', line 72

def parse_action_files
  @contexts.each do |context|
    actions_in_context = context.read_actions
    actions_in_context.each do |action_in_context|
      action = @actions.detect {|an_action| an_action.description == action_in_context[:description] and an_action.context == context}
      if (action) then
        context << action
        #log "Matched\t\t#{action}"
        #else
        #log "Unmatched\t#{action_string.description}" 
      end
    end
  end
   	
end

#persistObject



110
111
112
113
114
# File 'lib/persistence.rb', line 110

def persist
  @projects.each {|project| project.write(project_dir+directory_name(project.status)) if project.dirty?}
  @contexts.each {|context| context.write}
  @inbox.write
end

#project_dirObject



100
101
102
# File 'lib/persistence.rb', line 100

def  project_dir 
  "#{@base_dir}/@Projects/"
end

#readObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/persistence.rb', line 25

def read
  @inbox.read
  @projects = read_projects_with_statuses(project_dir, 
  [ :unprocessed, :done, :someday, :tickled, :delegated])
  #log @projects.active.join("\n")
  action_details = @projects.collect do |project| 
    actions_and_infos = project.read_actions
    actions = actions_and_infos[:actions]
    infos = actions_and_infos[:infos]
    project.infos = infos
    actions      
  end.flatten
  context_name_map = read_contexts action_details
  #log context_name_map
  @actions = []
  action_details.each do |action_detail| 
    context = context_name_map[action_detail[:context]]
    action = Action.new(action_detail[:description],context,
    action_detail[:project],action_detail[:status],action_detail[:info])
    @actions << action
    action.project << action
  end
  @contexts = context_name_map.values
  log "Read #{@projects.length} projects containing #{action_details.length} actions in #{@contexts.length} contexts"
end

#read_actions_in_done_folderObject



90
91
92
93
94
95
96
97
98
99
# File 'lib/persistence.rb', line 90

def read_actions_in_done_folder
  done_context = ContextFromDirectory.new("@Done",@base_dir)
  done_actions = done_context.read_actions
  real_done_actions = []
  done_actions.each do |action|
    real_done_actions << @actions.detect {|an_action| an_action.description == action[:description] and an_action.context.name == action[:context]}
    #log "Real action for #{action[:description]} (#{action[:context]}): #{real_action}"
  end
  real_done_actions
end

#read_contexts(action_details) ⇒ Object



63
64
65
66
67
68
69
70
# File 'lib/persistence.rb', line 63

def read_contexts(action_details)
  context_names = action_details.collect{|action| action[:context]}.uniq
  context_name_map = {}
  context_names.each do|context_name|
    context_name_map[context_name]= ContextFromDirectory.new(context_name,@base_dir)
  end
  context_name_map
end

#read_projects(folder, status) ⇒ Object



58
59
60
61
# File 'lib/persistence.rb', line 58

def read_projects(folder,status)   
  #log "In #{folder} reading projects with status #{status}"
  Dir["#{folder}/*.prj"].collect{|project_file_name| ProjectFromFile.new(utf_file_name(project_file_name),status)}
end

#read_projects_with_statuses(folder, statuses) ⇒ Object



51
52
53
54
55
56
57
# File 'lib/persistence.rb', line 51

def read_projects_with_statuses(folder,statuses)
  projects = []
  statuses.each do |status|
    projects += read_projects(project_dir+directory_name(status), status)
  end
  projects
end

#update_contextsObject



104
105
106
# File 'lib/persistence.rb', line 104

def update_contexts
  @contexts.each {|context| context.update}
end