提交 00bcb6f2 编写于 作者: M Mislav Marohnić

Avoid loading FileUtils; reimplement `mkdir_p`

Loading FileUtils can take more than 10 ms on Ruby 2.0.0, making the
require extremely wasteful for the purpose of just using a single method.
上级 f2421405
require 'forwardable' require 'forwardable'
require 'fileutils'
module Hub module Hub
# Client for the GitHub v3 API. # Client for the GitHub v3 API.
...@@ -381,10 +380,18 @@ module Hub ...@@ -381,10 +380,18 @@ module Hub
end end
def save def save
FileUtils.mkdir_p File.dirname(@filename) mkdir_p File.dirname(@filename)
File.open(@filename, 'w', 0600) {|f| f << yaml_dump(@data) } File.open(@filename, 'w', 0600) {|f| f << yaml_dump(@data) }
end end
def mkdir_p(dir)
dir.split('/').inject do |parent, name|
d = File.join(parent, name)
Dir.mkdir(d) unless File.exist?(d)
d
end
end
def yaml_load(string) def yaml_load(string)
hash = {} hash = {}
host = nil host = nil
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册