Class: DeployS3::Main
- Inherits:
-
Object
- Object
- DeployS3::Main
- Defined in:
- lib/deploy_s3/main.rb
Instance Method Summary collapse
- #commit_count ⇒ Object
- #connection ⇒ Object
- #diff ⇒ Object
- #environment ⇒ Object
- #filename ⇒ Object
-
#initialize(options) ⇒ Main
constructor
A new instance of Main.
- #key ⇒ Object
- #local_sha ⇒ Object
- #older_local_sha ⇒ Object
- #remote_sha ⇒ Object
- #reverse_diff ⇒ Object
- #run! ⇒ Object
- #save_sha ⇒ Object
- #up_to_date ⇒ Object
Constructor Details
#initialize(options) ⇒ Main
Returns a new instance of Main.
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/deploy_s3/main.rb', line 5 def initialize() config_path = [:config_file] || "./.deploy" @config = [:config] || YAML::load_file(config_path) raise "Missing s3: option in .deploy file" unless @config['s3'] @path = @config['s3'].split("/") @bucket = @path.shift @options = end |
Instance Method Details
#commit_count ⇒ Object
81 82 83 |
# File 'lib/deploy_s3/main.rb', line 81 def commit_count diff.split("\n").size end |
#connection ⇒ Object
39 40 41 |
# File 'lib/deploy_s3/main.rb', line 39 def connection @_connection ||= Fog::Storage.new(:provider => 'AWS') end |
#diff ⇒ Object
68 69 70 |
# File 'lib/deploy_s3/main.rb', line 68 def diff execute "git log --pretty=format:' %h %<(20)%an %ar\t %s' -10 #{remote_sha}..#{local_sha}" end |
#environment ⇒ Object
16 17 18 |
# File 'lib/deploy_s3/main.rb', line 16 def environment @options[:environment] end |
#filename ⇒ Object
51 52 53 |
# File 'lib/deploy_s3/main.rb', line 51 def filename [environment, 'sha'].join('.') end |
#key ⇒ Object
55 56 57 |
# File 'lib/deploy_s3/main.rb', line 55 def key [@path, filename].join("/") end |
#local_sha ⇒ Object
63 64 65 66 |
# File 'lib/deploy_s3/main.rb', line 63 def local_sha rev = @options[:rev] || @config[:branch] || 'head' execute("git rev-parse --verify #{rev}").chomp end |
#older_local_sha ⇒ Object
76 77 78 79 |
# File 'lib/deploy_s3/main.rb', line 76 def older_local_sha return false unless remote_sha execute("git merge-base --is-ancestor #{local_sha} #{remote_sha}") && $?.exitstatus == 0 end |
#remote_sha ⇒ Object
43 44 45 46 47 48 49 |
# File 'lib/deploy_s3/main.rb', line 43 def remote_sha return @_remote_sha if @_remote_sha directory = connection.directories.get(@bucket) file = directory.files.get(key) @_remote_sha = file.body if file end |
#reverse_diff ⇒ Object
72 73 74 |
# File 'lib/deploy_s3/main.rb', line 72 def reverse_diff execute "git log --pretty=format:' %h %<(20)%an %ar\t %s' -10 #{local_sha}..#{remote_sha}" end |
#run! ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/deploy_s3/main.rb', line 27 def run! if @config['before_hook'] `#{@config['before_hook']}` end save_sha if @config['after_hook'] `#{@config['after_hook']}` end end |
#save_sha ⇒ Object
20 21 22 23 24 25 |
# File 'lib/deploy_s3/main.rb', line 20 def save_sha directory = connection.directories.get(@bucket) file = directory.files.create(:key => key, :body => local_sha) @_remote_sha = nil end |
#up_to_date ⇒ Object
59 60 61 |
# File 'lib/deploy_s3/main.rb', line 59 def up_to_date local_sha == remote_sha end |