52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
|
# File 'lib/couch_tomato/js_view_source.rb', line 52
def self.diff
status_dict = {
:NEW_DOC => "new design:", :NEW_VIEW => "new view:",
:MOD_VIEW => "modified:", :DEL_DOC => "deleted:",
:DEL_VIEW => "deleted:", :NEW_DB => "new db:"
}
types = ["map", "reduce"]
puts "# Changes with respect to the filesystem:"
fs_database_names.each do |database_name|
db = database(database_name)
puts "#\t#{setw(status_dict[:NEW_DB], 14)}#{database_name}" unless is_db?(db)
fs_docs = fs_design_docs(database_name)
db_docs = is_db?(db) ? db_design_docs(db) : {}
diff = []
(fs_docs.keys - db_docs.keys).each do |design_name|
unless fs_docs[design_name]['views'].empty?
diff.push [:NEW_DOC, "#{database_name}/_#{design_name}"]
fs_docs[design_name]['views'].keys.each do |view|
(fs_docs[design_name]['views'][view].keys & types).each {|type|
diff.push [:NEW_VIEW, "#{database_name}/_#{design_name}/#{view}-#{type}"]}
end
end
end
(db_docs.keys - fs_docs.keys).each do |design_name|
diff.push [:DEL_DOC, "#{database_name}/_#{design_name}"] unless (design_name.to_s.include? "migrations")
end
(fs_docs.keys & db_docs.keys).each do |design_name|
common_view_keys = (fs_docs[design_name]['views'].keys & db_docs[design_name]['views'].keys)
fs_only_view_keys = fs_docs[design_name]['views'].keys - common_view_keys
db_only_view_keys = db_docs[design_name]['views'].keys - common_view_keys
unless fs_only_view_keys.empty?
methods = fs_only_view_keys.map do |key|
%w(map reduce).map {|method| fs_docs[design_name]['views'][key][method].nil? ? nil : "#{key}-#{method}"}.compact
end.flatten
methods.each {|method| diff.push [:NEW_VIEW, "#{database_name}/_#{design_name}/#{method}"] }
end
unless db_only_view_keys.empty?
methods = db_only_view_keys.map do |key|
%w(map reduce).map {|method| db_docs[design_name]['views'][key][method] ? "#{key}-#{method}" : nil}.compact
end
methods.each {|method| diff.push [:DEL_VIEW, "#{database_name}/_#{design_name}/#{method}"] }
end
common_view_keys.each do |common_key|
fs_view = fs_docs[design_name]['views'][common_key]
db_view = db_docs[design_name]['views'][common_key]
%w(map reduce).each do |method|
if db_view[method] && !fs_view[method]
diff.push [:DEL_VIEW, "#{database_name}/_#{design_name}/#{common_key}-#{method}"] and next
end
if fs_view[method] && !db_view[method]
diff.push [:NEW_VIEW, "#{database_name}/_#{design_name}/#{common_key}-#{method}"] and next
end
if fs_view["sha1-#{method}"] != db_view["sha1-#{method}"]
diff.push [:MOD_VIEW, "#{database_name}/_#{design_name}/#{common_key}-#{method}"] and next
end
end
end
end
diff.uniq!
diff.each do |status|
puts "#\t#{setw(status_dict[status.first], 14)}#{status.last}"
end
end
end
|