Class: Microstatic::Rake::S3DeployTask

Inherits:
Rake::TaskLib
  • Object
show all
Defined in:
lib/microstatic/rake.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ S3DeployTask

Returns a new instance of S3DeployTask.



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/microstatic/rake.rb', line 9

def initialize( opts = {} )
  if opts.is_a?(String) || opts.is_a?(Symbol)
    opts = { name: opts }
  end

  @name = opts.fetch( :name ) { :s3deploy }
  @aws_access_key_id = opts.fetch( :aws_access_key_id ) { ENV.fetch('AWS_ACCESS_KEY_ID') }
  @aws_secret_access_key = opts.fetch( :aws_secret_access_key ) { ENV.fetch('AWS_SECRET_ACCESS_KEY') }
  @bucket_name = opts.fetch( :bucket_name, false )
  @source_dir = opts.fetch( :source_dir, false )
end

Instance Attribute Details

#aws_access_key_idObject

Returns the value of attribute aws_access_key_id.



7
8
9
# File 'lib/microstatic/rake.rb', line 7

def aws_access_key_id
  @aws_access_key_id
end

#aws_secret_access_keyObject

Returns the value of attribute aws_secret_access_key.



7
8
9
# File 'lib/microstatic/rake.rb', line 7

def aws_secret_access_key
  @aws_secret_access_key
end

#bucket_nameObject

Returns the value of attribute bucket_name.



7
8
9
# File 'lib/microstatic/rake.rb', line 7

def bucket_name
  @bucket_name
end

#nameObject

Returns the value of attribute name.



7
8
9
# File 'lib/microstatic/rake.rb', line 7

def name
  @name
end

#source_dirObject

Returns the value of attribute source_dir.



7
8
9
# File 'lib/microstatic/rake.rb', line 7

def source_dir
  @source_dir
end

Instance Method Details

#defineObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/microstatic/rake.rb', line 21

def define
  require 'microstatic'

  raise 'must specify bucket_name' unless bucket_name
  raise 'must specify source_dir' unless source_dir
  raise 'must specify aws_access_key_id' unless aws_access_key_id
  raise 'must specify aws_secret_access_key' unless aws_secret_access_key

  aws_creds = {
    :access_key_id => aws_access_key_id,
    :secret_access_key => aws_secret_access_key
  }

  desc "deploy to the '#{bucket_name}' S3 bucket" unless ::Rake.application.last_comment
  task name do
    deployer = Microstatic::S3Deployer.new( source_dir, bucket_name, aws_creds )
    deployer.upload
  end
end