Module: Blue::LocalConfig::CapistranoIntegration

Defined in:
lib/capistrano/local_config.rb

Class Method Summary collapse

Class Method Details

.included(klass) ⇒ Object



5
6
7
8
9
# File 'lib/capistrano/local_config.rb', line 5

def self.included(klass)
  Blue.load_config!({
    :local_config => []
  })
end

.load(capistrano_config) ⇒ Object



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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/capistrano/local_config.rb', line 11

def self.load(capistrano_config)
  capistrano_config.load do

    set :local_config, Blue.config.local_config

    namespace :local_config do

      desc <<-DESC
Uploads local configuration files to the application's shared directory for \
later symlinking (if necessary). Called if local_config is set.
      DESC
      task :upload do
        Blue.config.local_config.each do |file|
          filename = File.basename(file)
          path = File.dirname(file)
          if File.exist?(file)
            run "mkdir -p '#{shared_path}/#{path}'" unless path.empty?
            parent.upload(file, "#{shared_path}/#{path}/#{filename}")
          end
        end
      end

      desc <<-DESC
Symlinks uploaded local configurations into the release directory.
      DESC
      task :symlink do
        Blue.config.local_config.each do |file|
          filename = File.basename(file)
          path = File.dirname(file)
          run "mkdir -p '#{latest_release}/#{path}'" unless path.empty?
          run "ls #{latest_release}/#{file} 2> /dev/null || ln -nfs #{shared_path}/#{path}/#{filename} #{latest_release}/#{file}"
        end
      end

      desc "Uplaod and symlink"
      task :upload_and_symlink do
        upload
        symlink
      end
    end

    after 'bundle:install', 'local_config:upload_and_symlink'
  end
end