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.("~/.ongaku_ryoho/server")
Class Method Summary collapse
-
.config_file_path ⇒ Object
Configuration file path.
-
.get ⇒ Object
Get.
-
.get_digest ⇒ Object
Get digest.
-
.save ⇒ Object
Save.
Class Method Details
.config_file_path ⇒ Object
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 |
.get ⇒ Object
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_digest ⇒ Object
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 |
.save ⇒ Object
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 |