Class: BigcommerceTool::Deployer

Inherits:
Object
  • Object
show all
Defined in:
lib/bigcommerce_tool/deployer.rb

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Deployer

Returns a new instance of Deployer.



3
4
5
6
7
# File 'lib/bigcommerce_tool/deployer.rb', line 3

def initialize(options)
  raise 'Missing config file' unless File.exists?('bigcommerce.yml') 
  @branch = options[:branch] || ENV['CIRCLE_BRANCH']
  @config = YAML.load_file(options[:config_path] || 'bigcommerce.yml')
end

Instance Method Details

#deployObject



9
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
# File 'lib/bigcommerce_tool/deployer.rb', line 9

def deploy
  return unless env_name

  Net::DAV.start(URI("https://#{url}/dav/")) do |dav|
    dav.credentials(ENV['USERNAME'], password)
    puts "push to: #{url}"
    changed_files.each do |file|
      begin
        if File.exists?(file)
          if file.include?(' ')
            puts "skipping: #{file}, file has a space in the name."
            next
          else
            create_path_if_missing(dav, file)
            dav.put_string(file, File.open(file, 'r').read)
            puts "add/update #{file}"
          end
        else
          dav.delete(file) if dav.exists?(file)
          puts "remove: #{file}"
        end
      rescue Exception => e
        puts "file: #{file}"
        puts e.message
        puts e.backtrace
        raise e
      end
    end
  end
end