forked from seamusabshere/warehouse
-
Notifications
You must be signed in to change notification settings - Fork 1
/
mock.rb
63 lines (50 loc) · 1.22 KB
/
mock.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
require 'yaml'
module Silo
module Adapters
module Mock
module NodeMethods
end
def latest_revision
config[:latest_revision]
end
def dir?(node)
File.directory?(node.full_path)
end
def file?(node)
File.file?(node.full_path)
end
def exists?(node)
File.exist?(node.full_path)
end
def child_node_names_for(node)
Dir.chdir node.full_path do
Dir["*"]
end
end
def blame_for(node)
info_for(node)[:blame]
end
def full_path_for(node)
File.join(@options[:path], node.path)
end
def latest_revision_for(node)
info_for(node)[:revision].to_i
end
[:author, :message, :changed_at].each do |attr|
define_method "#{attr}_for" do |node|
info_for(node)[attr]
end
end
def content_for(node)
IO.read(node.full_path) if file?(node)
end
protected
def info_for(node)
config[:files][node.path] || {}
end
def config
@config ||= YAML.load_file(File.join(@options[:path], 'config.yml'))
end
end
end
end