Class: Mogwai

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

Defined Under Namespace

Classes: Config

Constant Summary collapse

CONFIG_PATHS =
["Mogfile", "Mogfile.yml", "mogfile", "mogfile.yml"]

Class Method Summary collapse

Class Method Details

.deploy(bucket = nil) ⇒ Object



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
# File 'lib/mogwai.rb', line 22

def self.deploy bucket = nil
  config = Mogwai::Config.new
  config.read
  bucket ||= config[:BUCKET]

  # Deploy built assets to s3
  STDOUT.sync = true
  AWS::S3::Base.establish_connection!(
    :access_key_id     => config[:AWS_ACCESS_KEY_ID],
    :secret_access_key => config[:AWS_SECRET_ACCESS_KEY]
  )

  build_dir = config[:BUILD_DIR].gsub(/([^\/])$/, '\1/')
  build_glob = build_dir + "**/*"

  Dir.glob(build_glob).each do |file|
    if File.file?(file)
      remote_file = file.gsub(build_dir, "")

      AWS::S3::S3Object.store(
        remote_file,
        open(file),
        bucket,
        :access => :public_read
      )
    end
  end
  STDOUT.sync = false 
  puts "Mogwai successfully deployed to " + bucket
  return true
end