Class: Amiba::Site::S3Upload

Inherits:
Thor::Group
  • Object
show all
Includes:
Generator, Repo
Defined in:
lib/amiba/site.rb

Instance Method Summary collapse

Methods included from Repo

#add_and_commit, #init, #last_commit_date, #last_commit_dates, #pull, #push, #repo

Methods included from Generator

included

Instance Method Details

#completeObject



93
94
95
96
# File 'lib/amiba/site.rb', line 93

def complete
  host = "http://#{bucket}.s3-website-#{Fog.credentials[:region]}.amazonaws.com/"
  say_status "Available at", host, :green
end

#configure_s3Object



66
67
68
69
70
71
72
73
74
75
# File 'lib/amiba/site.rb', line 66

def configure_s3
  if ! @s3.directories.get bucket 
    @bucket = @s3.directories.create(:key=>bucket, :public=>true, :location=>location)
    say_status "Created", @bucket.key, :green
    @s3.put_bucket_website(bucket,"index.html")
    say_status "Configured", @bucket.key, :green
  else
    @bucket = @s3.directories.get bucket 
  end
end

#createObject



62
63
64
# File 'lib/amiba/site.rb', line 62

def create
  invoke Amiba::Site::Generate
end

#git_pushObject



88
89
90
91
# File 'lib/amiba/site.rb', line 88

def git_push
  push
  say_status "Changes pushed to git", "", :green
end

#init_s3Object



55
56
57
58
59
60
# File 'lib/amiba/site.rb', line 55

def init_s3
  cf = File.expand_path(File.join(Dir.pwd, ".fog"))
  Fog.credentials_path = cf if File.exists? cf
  Fog.credential = options[:credentials].to_sym
  @s3 ||= Fog::Storage.new(:provider=>'AWS')
end

#upload_filesObject



77
78
79
80
81
82
83
84
85
86
# File 'lib/amiba/site.rb', line 77

def upload_files
  Dir[File.join(Amiba::Configuration.site_dir, "public", "**/*")].each do |ent|
    next if File.directory? ent
    path = File.expand_path ent
    name = File.relpath(path, File.join(Amiba::Configuration.site_dir, "public"))
    data = File.open path
    file = @bucket.files.create(:key=>name, :body=>data, :public=>true)
    say_status "Uploaded", name, :green
  end
end