class WorkLogFileDao
Constants
- DB_FILE_NAME
- DB_FOLDER
- FULL_DB_FILE_PATH
- HOME_FOLDER
Public Class Methods
new()
click to toggle source
# File lib/work_log_file_dao.rb, line 12 def initialize db_folder_full_path = "#{HOME_FOLDER}/#{DB_FOLDER}" unless File.directory?(db_folder_full_path) FileUtils.mkdir_p(db_folder_full_path) end end
Public Instance Methods
delete(id)
click to toggle source
# File lib/work_log_file_dao.rb, line 40 def delete(id) PStore.new(FULL_DB_FILE_PATH).transaction do |store| raise ArgumentError, "Id #{id} not found" if store[id].nil? store.delete(id) end end
find_by_month_and_year(month, year)
click to toggle source
# File lib/work_log_file_dao.rb, line 48 def find_by_month_and_year(month, year) store = PStore.new(FULL_DB_FILE_PATH) list = [] store.transaction(true) do store.roots.map do |root| if store[root].date.month == month && store[root].date.year == year list << store[root] end end end list end
find_by_year(year)
click to toggle source
# File lib/work_log_file_dao.rb, line 61 def find_by_year(year) store = PStore.new(FULL_DB_FILE_PATH) list = [] store.transaction(true) do store.roots .map do |root| list << store[root] if store[root].date.year == year end end list end
list(date)
click to toggle source
# File lib/work_log_file_dao.rb, line 23 def list(date) store = PStore.new(FULL_DB_FILE_PATH) list = [] store.transaction(true) do store.roots .map { |root| list << store[root] if store[root].date == date } end list end
list_all()
click to toggle source
# File lib/work_log_file_dao.rb, line 33 def list_all store = PStore.new(FULL_DB_FILE_PATH) list = [] store.transaction(true) { store.roots.map { |root| list << store[root] } } list end
save(work_log)
click to toggle source
# File lib/work_log_file_dao.rb, line 19 def save(work_log) PStore.new(FULL_DB_FILE_PATH).transaction { |store| store[work_log.id] = work_log } end