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.



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

def initialize(dir)
  @dir = dir
end

Instance Method Details

#read(key) ⇒ Object



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

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

#write(key, value) ⇒ Object



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

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