Sha256: 8f292670af6d2eea19529a0e6440511c39e0c53b8d9b21a51244618e42fa87e0

Contents?: true

Size: 1.46 KB

Versions: 9

Compression:

Stored size: 1.46 KB

Contents

require 'nokogiri'
module Capistrano
  module Cluster
    module Files
      module DSL

        def remote_file(url, file, checksum: nil)
          file = File.expand_path(file)

          if test "[ -f '#{file}' ]"
            if checksum
              return if checksum == capture("sha256sum '#{file}' | awk '{ print $1}'")
              execute :rm, "-f", file
            else
              return
            end
          end
          execute :mkdir, "-p", File.dirname(file)
          execute :wget, "-q", "-o", "/dev/null" , "-O", file, url
        end

        def upload_as(user, file, remote_file, options={})
          group = options.fetch(:group, user)

          tmp_name = "/tmp/#{SecureRandom.uuid}"
          upload! file, tmp_name

          sudo :mv, tmp_name, remote_file

          unless test "[[ -d #{File.dirname(remote_file)} ]]"
            sudo :mkdir, "-p", File.dirname(remote_file)
            sudo :chown, "-R", "#{user}:#{group}", File.dirname(remote_file)

          end

          sudo :chown, "#{user}:#{group}", remote_file
          sudo :chmod, options.fetch(:mode, 644), remote_file

        end

        def item(identifier)
          consume = false
          xml = File.read(caller.first.split(":").first).lines.select { |l| consume ||= l =~/^__END__$/ || consume}[1..-1].join()
          doc = Nokogiri::HTML(xml)
          doc.css("##{identifier}").inner_html
        end

      end
    end
  end
end



include Capistrano::Cluster::Files::DSL


Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
capistrano-cluster-0.0.18 lib/capistrano/cluster/files.rb
capistrano-cluster-0.0.17 lib/capistrano/cluster/files.rb
capistrano-cluster-0.0.16 lib/capistrano/cluster/files.rb
capistrano-cluster-0.0.15 lib/capistrano/cluster/files.rb
capistrano-cluster-0.0.14 lib/capistrano/cluster/files.rb
capistrano-cluster-0.0.13 lib/capistrano/cluster/files.rb
capistrano-cluster-0.0.12 lib/capistrano/cluster/files.rb
capistrano-cluster-0.0.11 lib/capistrano/cluster/files.rb
capistrano-cluster-0.0.10 lib/capistrano/cluster/files.rb