Module: OngakuRyohoServer::List

Defined in:
lib/ongaku_ryoho_server/list.rb

Overview

{ List }

Info

Module for handling the lists, tracks data saved in json files

Constant Summary collapse

CONFIG_PATH =
File.expand_path("~/.ongaku_ryoho/server")

Class Method Summary collapse

Class Method Details

.config_file_pathObject

Configuration file path

> Build path to config file



29
30
31
# File 'lib/ongaku_ryoho_server/list.rb', line 29

def self.config_file_path
  "#{CONFIG_PATH}/#{self.get_digest}.json"
end

.getObject

Get

> Get the list for the current directory



39
40
41
42
43
44
45
# File 'lib/ongaku_ryoho_server/list.rb', line 39

def self.get
  path = self.config_file_path
  if File.file?(path)
    file_contents = File.open(path, "r").read
    OngakuRyohoServer::Process.encode_string(file_contents, "")
  end
end

.get_digestObject

Get digest

> Creates a digest from the path of the current directory



19
20
21
# File 'lib/ongaku_ryoho_server/list.rb', line 19

def self.get_digest
  digested_path = Digest::SHA1.hexdigest(Dir.pwd)
end

.saveObject

Save

> Save the list for the current directory



53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/ongaku_ryoho_server/list.rb', line 53

def self.save
  path = self.config_file_path
  file_list = OngakuRyohoServer::Process.directory
  collection = Oj.dump(OngakuRyohoServer::Process.files(file_list))

  # make path
  FileUtils.mkpath(CONFIG_PATH)

  # make file
  File.open(path, "w") do |f|
    f.write collection
  end
end