Class: Docman::DocrootConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/docman/docroot_config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(docroot_dir, deploy_target) ⇒ DocrootConfig

Returns a new instance of DocrootConfig.



10
11
12
13
14
15
16
17
# File 'lib/docman/docroot_config.rb', line 10

def initialize(docroot_dir, deploy_target)
  @docroot_dir = docroot_dir
  @deploy_target = deploy_target
  @docroot_config_dir = File.join(docroot_dir, 'config')
  update
  @names = {}
  @structure = structure_build File.join(@docroot_config_dir, 'master')
end

Instance Attribute Details

#structureObject (readonly)

Returns the value of attribute structure.



8
9
10
# File 'lib/docman/docroot_config.rb', line 8

def structure
  @structure
end

Instance Method Details

#chain(info) ⇒ Object



56
57
58
59
60
61
62
63
64
# File 'lib/docman/docroot_config.rb', line 56

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

#info_by(name) ⇒ Object



78
79
80
# File 'lib/docman/docroot_config.rb', line 78

def info_by(name)
  @names[name]
end

#root(info) ⇒ Object



66
67
68
69
70
71
72
# File 'lib/docman/docroot_config.rb', line 66

def root(info)
  chain(info).each do |name, item|
    if item['type'] == 'root'
      return item
    end
  end
end

#root_dirObject



74
75
76
# File 'lib/docman/docroot_config.rb', line 74

def root_dir
  @structure[:data]
end

#states_dependin_on(name, version) ⇒ Object



82
83
84
85
86
87
88
# File 'lib/docman/docroot_config.rb', line 82

def states_dependin_on(name, version)
  states = {}
  @names[name]['states'].each do |state, info|
    states[state] = info if info['version'] == version
  end
  states
end

#structure_build(path, prefix = '', parent = nil) ⇒ Object



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
# File 'lib/docman/docroot_config.rb', line 23

def structure_build(path, prefix = '', parent = nil)
  return unless File.file? File.join(path, 'info.yaml')

  info = YAML::load_file(File.join(path, 'info.yaml'))
  name = File.basename path
  prefix = prefix.size > 0 ? File.join(prefix, name) : name
  info['full_path'] = path
  info['build_path'] = prefix
  info['full_build_path'] = File.join(@docroot_dir, prefix)
  info['temp_path'] = File.join(@docroot_dir, 'tmp', info['build_path'])
  info['name'] = name
  info['parent'] = parent

  i = Docman::Info.new(info)

  @names[name.to_s] = i

  data = {:data => info, :info => 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)
      unless dir_hash == nil
        children << dir_hash
      end
    end
  end
  data
end

#updateObject



19
20
21
# File 'lib/docman/docroot_config.rb', line 19

def update
  GitUtil.update @docroot_config_dir
end