aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/descriptions.rb
diff options
context:
space:
mode:
authorXu Cheng2015-09-09 14:00:26 +0800
committerXu Cheng2015-09-10 13:37:58 +0800
commit65996b5887ac6e4b669e9460b8e2a4fbc7171984 (patch)
tree834fa20d86d76b182da970887704324836615d12 /Library/Homebrew/descriptions.rb
parentc5536e1e08a13352cf241a2c3f7b2aa75a8e31d6 (diff)
downloadbrew-65996b5887ac6e4b669e9460b8e2a4fbc7171984.tar.bz2
use json to cache descriptions
We need to use `atomic_write` when saving the cache. And it seems that CSV module doesn't support dump, so let's use JSON instead.
Diffstat (limited to 'Library/Homebrew/descriptions.rb')
-rw-r--r--Library/Homebrew/descriptions.rb13
1 files changed, 3 insertions, 10 deletions
diff --git a/Library/Homebrew/descriptions.rb b/Library/Homebrew/descriptions.rb
index 5f7f44c4d..09ea7ed56 100644
--- a/Library/Homebrew/descriptions.rb
+++ b/Library/Homebrew/descriptions.rb
@@ -1,9 +1,8 @@
require "formula"
require "formula_versions"
-require "csv"
class Descriptions
- CACHE_FILE = HOMEBREW_CACHE + "desc_cache"
+ CACHE_FILE = HOMEBREW_CACHE + "desc_cache.json"
def self.cache
@cache || self.load_cache
@@ -13,9 +12,7 @@ class Descriptions
# return nil.
def self.load_cache
if CACHE_FILE.exist?
- @cache = {}
- CSV.foreach(CACHE_FILE) { |name, desc| @cache[name] = desc }
- @cache
+ @cache = Utils::JSON.load(CACHE_FILE.read)
end
end
@@ -23,11 +20,7 @@ class Descriptions
# directory.
def self.save_cache
HOMEBREW_CACHE.mkpath
- CSV.open(CACHE_FILE, 'w') do |csv|
- @cache.each do |name, desc|
- csv << [name, desc]
- end
- end
+ CACHE_FILE.atomic_write Utils::JSON.dump(@cache)
end
# Create a hash mapping all formulae to their descriptions;