Class: ConsoleRtm::ContextStorage

Inherits:
Object
  • Object
show all
Defined in:
lib/rmilk/context_storage.rb

Instance Method Summary collapse

Constructor Details

#initialize(file_name, history_size = 10) ⇒ ContextStorage

Returns a new instance of ContextStorage.



5
6
7
8
# File 'lib/rmilk/context_storage.rb', line 5

def initialize(file_name, history_size = 10)
  @history_size = history_size
  @store = PStore.new(file_name)
end

Instance Method Details

#add_to_history(text) ⇒ Object



41
42
43
44
45
46
47
# File 'lib/rmilk/context_storage.rb', line 41

def add_to_history(text)
  @store.transaction do
    h = @store["history"]
    (h ||= []) << text
    @store["history"] = h.last(@history_size)
  end
end

#get_historyObject



49
50
51
52
53
# File 'lib/rmilk/context_storage.rb', line 49

def get_history
  @store.transaction do
    @store["history"].reverse 
  end
end

#get_list_id(list_name) ⇒ Object



23
24
25
26
27
# File 'lib/rmilk/context_storage.rb', line 23

def get_list_id(list_name)
  @store.transaction do
    @store["list_name_#{list_name}"]
  end
end

#get_list_name(list_id) ⇒ Object



17
18
19
20
21
# File 'lib/rmilk/context_storage.rb', line 17

def get_list_name(list_id)
  @store.transaction do
    @store["list_id_#{list_id}"]
  end
end

#get_tasksObject



35
36
37
38
39
# File 'lib/rmilk/context_storage.rb', line 35

def get_tasks
  @store.transaction do
    @store["tasks"]
  end
end

#recreateObject



55
56
57
58
59
# File 'lib/rmilk/context_storage.rb', line 55

def recreate
  path = @store.path
  File.delete path if File.exists? path
  @store = PStore.new(path)
end

#save_list_name(list_id, list_name) ⇒ Object



10
11
12
13
14
15
# File 'lib/rmilk/context_storage.rb', line 10

def save_list_name(list_id, list_name)
  @store.transaction do
    @store["list_id_#{list_id}"] = list_name
    @store["list_name_#{list_name}"] = list_id
  end
end

#save_tasks(tasks) ⇒ Object



29
30
31
32
33
# File 'lib/rmilk/context_storage.rb', line 29

def save_tasks(tasks)
  @store.transaction do
    @store["tasks"] = tasks
  end
end