Class: Popo::Initializer

Inherits:
Object
  • Object
show all
Includes:
Constants
Defined in:
lib/popo/initializer.rb

Constant Summary

Constants included from Constants

Constants::DEFAULT_CONFIG_FILE, Constants::DEFAULT_POPO_TARGET, Constants::POPORC, Constants::POPO_COMMANDS, Constants::POPO_CONFIG, Constants::POPO_DIR_KEY, Constants::POPO_KEY_VALUES, Constants::POPO_WORK_PATH, Constants::POPO_YML_FILE

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config, options, db) ⇒ Initializer

Returns a new instance of Initializer.



9
10
11
12
13
14
15
16
# File 'lib/popo/initializer.rb', line 9

def initialize(config, options, db)
  @options = options
  @db = db
  @manifest = config['manifests'][@options[:manifest]]
  @default_target = @options[:target] || 'development'
  @deploy_path = File.absolute_path(@options[:path])
  @location = @options[:location] || nil
end

Class Method Details

.boot(config, options, db) ⇒ Object



5
6
7
# File 'lib/popo/initializer.rb', line 5

def self.boot(config, options, db)
  self.new(config, options, db)
end

Instance Method Details



18
19
20
21
22
# File 'lib/popo/initializer.rb', line 18

def print_variables
  instance_variables.each do |i|
    say instance_variable_get(i)
  end
end

#setupObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/popo/initializer.rb', line 24

def setup
  print_variables if @options[:verbose]

  clone_path = File.join(@deploy_path, POPO_WORK_PATH)
  GitUtils.git_clone(@manifest['git'], clone_path, @manifest['branch'])

  @db.boot_database
  @db.migrate_database
  repos = @db.get_children("repos")

  repos.each do |r|
    git = @db.get("repos.#{r}.git")
    branch = @db.get("repos.#{r}.branch")
    clone_path = File.join(@deploy_path, r)
    GitUtils.git_clone(git, clone_path, branch)
  end

  write_config
end

#write_configObject



44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/popo/initializer.rb', line 44

def write_config
  popo = {}
  popo['target'] = @default_target
  popo['path'] = @deploy_path
  popo['location'] = @location if !@location.nil?

  yml_path = File.join(@deploy_path, POPO_WORK_PATH, POPO_YML_FILE)

  File.open(yml_path, "w") do |f|
    YAML.dump(popo, f)
  end
end