Class: Docman::DocrootConfig
- Inherits:
-
Object
- Object
- Docman::DocrootConfig
- Defined in:
- lib/docman/docroot_config.rb
Instance Attribute Summary collapse
-
#deploy_target ⇒ Object
readonly
Returns the value of attribute deploy_target.
-
#docroot_dir ⇒ Object
readonly
Returns the value of attribute docroot_dir.
-
#raw_infos ⇒ Object
readonly
Returns the value of attribute raw_infos.
-
#root ⇒ Object
readonly
Returns the value of attribute root.
-
#structure ⇒ Object
readonly
Returns the value of attribute structure.
Instance Method Summary collapse
- #chain(info) ⇒ Object
- #config_hash ⇒ Object
- #deploy_target_name ⇒ Object
- #info_by(name) ⇒ Object
-
#initialize(docroot_dir, deploy_target_name = nil, options = nil) ⇒ DocrootConfig
constructor
A new instance of DocrootConfig.
- #project(name) ⇒ Object
- #states_dependin_on(name, version) ⇒ Object
- #structure_build(path, prefix = '', parent = nil) ⇒ Object
- #structure_build_from_config_file(path, prefix = '', parent = nil, parent_key = 'master') ⇒ Object
- #update(options = '') ⇒ Object
Constructor Details
#initialize(docroot_dir, deploy_target_name = nil, options = nil) ⇒ DocrootConfig
Returns a new instance of DocrootConfig.
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 |
# File 'lib/docman/docroot_config.rb', line 10 def initialize(docroot_dir, deploy_target_name = nil, = nil) @override = {} if && ['config'] @override = JSON.parse(['config']) end @docroot_dir = docroot_dir #@deploy_target = deploy_target @docroot_config_dir = File.join(docroot_dir, 'config') Dir.chdir @docroot_config_dir update(' origin master') if File.file? File.join(@docroot_config_dir, 'config.yaml') Docman::Application.instance.config.merge_config_from_file(@docroot_config_dir, 'config.yaml', ) end if deploy_target_name @deploy_target = Application.instance.config['deploy_targets'][deploy_target_name] raise "Wrong deploy target: #{deploy_target_name}" if @deploy_target.nil? @deploy_target['name'] = deploy_target_name end @names = {} @raw_infos = {} master_file = File.join(@docroot_config_dir, 'master') if File.directory? master_file @structure = structure_build(File.join(@docroot_config_dir, 'master')) else @structure = structure_build_from_config_file(File.join(@docroot_config_dir, 'master')) end end |
Instance Attribute Details
#deploy_target ⇒ Object (readonly)
Returns the value of attribute deploy_target.
8 9 10 |
# File 'lib/docman/docroot_config.rb', line 8 def deploy_target @deploy_target end |
#docroot_dir ⇒ Object (readonly)
Returns the value of attribute docroot_dir.
8 9 10 |
# File 'lib/docman/docroot_config.rb', line 8 def docroot_dir @docroot_dir end |
#raw_infos ⇒ Object (readonly)
Returns the value of attribute raw_infos.
8 9 10 |
# File 'lib/docman/docroot_config.rb', line 8 def raw_infos @raw_infos end |
#root ⇒ Object (readonly)
Returns the value of attribute root.
8 9 10 |
# File 'lib/docman/docroot_config.rb', line 8 def root @root end |
#structure ⇒ Object (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
139 140 141 142 143 144 145 146 147 |
# File 'lib/docman/docroot_config.rb', line 139 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 |
#config_hash ⇒ Object
166 167 168 |
# File 'lib/docman/docroot_config.rb', line 166 def config_hash Digest::MD5.hexdigest(Marshal::dump(@raw_infos)) end |
#deploy_target_name ⇒ Object
170 171 172 |
# File 'lib/docman/docroot_config.rb', line 170 def deploy_target_name @deploy_target.name end |
#info_by(name) ⇒ Object
149 150 151 |
# File 'lib/docman/docroot_config.rb', line 149 def info_by(name) @names[name] end |
#project(name) ⇒ Object
153 154 155 156 |
# File 'lib/docman/docroot_config.rb', line 153 def project(name) raise "There is no project with name '#{name}' exists in config" unless @names.has_key? name @names[name] end |
#states_dependin_on(name, version) ⇒ Object
158 159 160 161 162 163 164 |
# File 'lib/docman/docroot_config.rb', line 158 def states_dependin_on(name, version) states = {} project(name).states.each do |state, info| states[state] = info if info['version'] == version end states end |
#structure_build(path, prefix = '', parent = nil) ⇒ Object
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 134 135 136 137 |
# File 'lib/docman/docroot_config.rb', line 94 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[File.basename path] = 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 info['full_build_path'] = File.join(@docroot_dir, prefix) info['temp_path'] = File.join(@docroot_dir, 'tmp', info['build_path']) info['states_path'] = File.join(@docroot_dir, 'states', info['build_path']) info['name'] = name info['parent'] = parent info['order'] = info.has_key?('order') ? info['order'] : 10 info['children'] = children if @override['projects'] && @override['projects'].key?(info['name']) info.merge! @override['projects'][info['name']] end i = Docman::Info.new(info) @root = i if parent.nil? i['root'] = @root @names[name.to_s] = i 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 i end |
#structure_build_from_config_file(path, prefix = '', parent = nil, parent_key = 'master') ⇒ Object
46 47 48 49 50 51 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 |
# File 'lib/docman/docroot_config.rb', line 46 def structure_build_from_config_file(path, prefix = '', parent = nil, parent_key = 'master') config = Docman::Application.instance.config return if config['components'][parent_key].nil? children = [] info = config['components'][parent_key] @raw_infos[parent_key] = info unless info['status'].nil? return if info['status'] == 'disabled' end name = parent_key prefix = prefix.size > 0 ? File.join(prefix, name) : name info['full_path'] = path info['docroot_config'] = self 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['states_path'] = File.join(@docroot_dir, 'states', info['build_path']) info['name'] = name info['parent'] = parent info['order'] = info.has_key?('order') ? info['order'] : 10 info['children'] = children if @override['projects'] && @override['projects'].key?(info['name']) info.merge! @override['projects'][info['name']] end i = Docman::Info.new(info) @root = i if parent.nil? i['root'] = @root @names[name.to_s] = i # 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 i end |
#update(options = '') ⇒ Object
41 42 43 44 |
# File 'lib/docman/docroot_config.rb', line 41 def update( = '') GitUtil.exec("reset --hard", false) GitUtil.update @docroot_config_dir, end |