lib/docman/docroot_config.rb in docman-0.0.5 vs lib/docman/docroot_config.rb in docman-0.0.6
- old
+ new
@@ -3,18 +3,21 @@
module Docman
class DocrootConfig
- attr_reader :structure, :deploy_target
-
+ attr_reader :structure, :deploy_target, :docroot_dir, :root
def initialize(docroot_dir, deploy_target)
@docroot_dir = docroot_dir
@deploy_target = deploy_target
@docroot_config_dir = File.join(docroot_dir, 'config')
update
+ if File.file? File.join(@docroot_config_dir, 'config.yaml')
+ Docman::Application.instance.config.merge_config_from_file(File.join(@docroot_config_dir, 'config.yaml'))
+ end
@names = {}
+ @raw_infos = []
@structure = structure_build File.join(@docroot_config_dir, 'master')
end
def update
GitUtil.update @docroot_config_dir
@@ -23,10 +26,14 @@
def structure_build(path, prefix = '', parent = nil)
return unless File.file? File.join(path, 'info.yaml')
children = []
info = YAML::load_file(File.join(path, 'info.yaml'))
+ @raw_infos << YAML::load_file(File.join(path, 'info.yaml'))
+ unless info['status'].nil?
+ return if info['status'] == 'disabled'
+ end
name = File.basename path
prefix = prefix.size > 0 ? File.join(prefix, name) : name
info['full_path'] = path
info['docroot_config'] = self
info['build_path'] = prefix
@@ -35,15 +42,15 @@
info['name'] = name
info['parent'] = parent
info['children'] = children
i = Docman::Info.new(info)
+ @root = i if parent.nil?
+ i['root'] = @root
@names[name.to_s] = i
- data = [i]
- # data[:children] = children
Dir.foreach(path) do |entry|
next if (entry == '..' || entry == '.')
full_path = File.join(path, entry)
if File.directory?(full_path)
dir_hash = structure_build(full_path, prefix, i)
@@ -53,42 +60,33 @@
end
end
i
end
-
def chain(info)
chain = {}
chain[info['name']] = info
while info['parent'] do
chain[info['parent']['name']] = info['parent']
info = info['parent']
end
Hash[chain.to_a.reverse!]
end
- def root(info)
- chain(info).each do |name, item|
- if item['type'] == 'root'
- return item
- end
- end
- end
-
- def root_dir
- @structure[:data]
- end
-
def info_by(name)
@names[name]
end
def states_dependin_on(name, version)
states = {}
@names[name]['states'].each do |state, info|
states[state] = info if info['version'] == version
end
states
+ end
+
+ def config_hash
+ Digest::MD5.hexdigest(Marshal::dump(@raw_infos))
end
end
end
\ No newline at end of file