Class: XiWechatCorp::API::CLI::FileCache
- Inherits:
-
Object
- Object
- XiWechatCorp::API::CLI::FileCache
- Defined in:
- lib/xi_wechat_corp/api/cli.rb
Instance Method Summary collapse
-
#initialize(dir) ⇒ FileCache
constructor
A new instance of FileCache.
- #read(key) ⇒ Object
- #write(key, value) ⇒ Object
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 |