Class: XiWechatCorp::API::CLI::FileCache

Inherits:
Object
  • Object
show all
Defined in:
lib/xi_wechat_corp/api/cli.rb

Instance Method Summary collapse

Constructor Details

#initialize(dir) ⇒ FileCache

Returns a new instance of FileCache.



12
13
14
# File 'lib/xi_wechat_corp/api/cli.rb', line 12

def initialize(dir)
  @dir = dir
end

Instance Method Details

#read(key) ⇒ Object



16
17
18
19
20
21
# File 'lib/xi_wechat_corp/api/cli.rb', line 16

def read(key) 
  path = File.join(@dir, key)
  if File.exists?(path)
    File.read(key)
  end
end

#write(key, value) ⇒ Object



23
24
25
26
27
# File 'lib/xi_wechat_corp/api/cli.rb', line 23

def write(key, value)
  path = File.join(@dir, key)
  FileUtils.mkdir_p(File.dirname(path))
  File.open(path, 'w') { |f| f.write(value) }
end