Class: Docman::DocrootController

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(docroot_dir, deploy_target_name, options = {}) ⇒ DocrootController

Returns a new instance of DocrootController.



16
17
18
19
20
21
22
23
24
# File 'lib/docman/docroot_controller.rb', line 16

def initialize(docroot_dir, deploy_target_name, options = {})
  @deploy_target = Docman::Application.instance.config['deploy_targets'][deploy_target_name]
  Docman::Application.instance.deploy_target = @deploy_target
  docroot_config = DocrootConfig.new(docroot_dir, @deploy_target)
  @deployer = Object.const_get("Docman::Deployers::#{@deploy_target['handler']}").new(@deploy_target)
  @docroot_dir = docroot_dir
  @temp_dir = File.join(docroot_dir, 'tmp')
  @docroot_config = docroot_config
end

Instance Attribute Details

#docroot_dirObject (readonly)

Returns the value of attribute docroot_dir.



14
15
16
# File 'lib/docman/docroot_controller.rb', line 14

def docroot_dir
  @docroot_dir
end

#temp_dirObject (readonly)

Returns the value of attribute temp_dir.



14
15
16
# File 'lib/docman/docroot_controller.rb', line 14

def temp_dir
  @temp_dir
end

Instance Method Details

#build(state) ⇒ Object



34
35
36
37
# File 'lib/docman/docroot_controller.rb', line 34

def build(state)
  build_recursive(state)
  @deployer.push(@docroot_config.root_dir, state)
end

#build_dir(state, info) ⇒ Object



59
60
61
62
# File 'lib/docman/docroot_controller.rb', line 59

def build_dir(state, info)
  info.state = state
  @deployer.build(@docroot_config.root(info), info)
end

#build_recursive(state, dir = nil) ⇒ Object



39
40
41
42
43
44
45
46
# File 'lib/docman/docroot_controller.rb', line 39

def build_recursive(state, dir = nil)
  dir = dir ? dir : @docroot_config.structure
  build_dir(state, dir[:info])

  dir[:children].each do |child|
    build_recursive(state, child)
  end
end

#deploy(name, type, version) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/docman/docroot_controller.rb', line 26

def deploy(name, type, version)
  puts "Deploy #{name}, type: #{type}"
  @docroot_config.states_dependin_on(name, version).each do |state_name, state|
    deploy_dir_chain(state_name, @docroot_config.info_by(name))
    @deployer.push(@docroot_config.root_dir, state_name)
  end
end

#deploy_dir_chain(state, info) ⇒ Object



48
49
50
51
52
53
54
55
56
57
# File 'lib/docman/docroot_controller.rb', line 48

def deploy_dir_chain(state, info)
  @docroot_config.chain(info).each do |name, item|
    if item.need_rebuild?
      build_recursive(state, item)
      return
    elsif
      build_dir(state, item)
    end
  end
end