Class: Stevenson::Deployer::S3

Inherits:
Object
  • Object
show all
Includes:
Base
Defined in:
lib/stevenson/deployers/s3.rb

Instance Attribute Summary collapse

Attributes included from Base

#options

Instance Method Summary collapse

Methods included from Base

included

Constructor Details

#initialize(options) ⇒ S3

Returns a new instance of S3.



10
11
12
13
# File 'lib/stevenson/deployers/s3.rb', line 10

def initialize(options)
  @deployment_bucket_name, @deployment_key, @deployment_access_key, @deployment_access_secret = options["s3"]
  super
end

Instance Attribute Details

#deployment_bucket_nameObject (readonly)

Returns the value of attribute deployment_bucket_name.



8
9
10
# File 'lib/stevenson/deployers/s3.rb', line 8

def deployment_bucket_name
  @deployment_bucket_name
end

#deployment_keyObject (readonly)

Returns the value of attribute deployment_key.



8
9
10
# File 'lib/stevenson/deployers/s3.rb', line 8

def deployment_key
  @deployment_key
end

Instance Method Details

#deploy!(directory) ⇒ Object



15
16
17
18
19
20
21
22
23
# File 'lib/stevenson/deployers/s3.rb', line 15

def deploy!(directory)
  entries_for(directory).each do |file_path, file_name|
    s3_bucket.files.create(
      key:    File.join(deployment_key, file_name),
      body:   File.read(file_path),
      public: true,
    ) if File.file?(file_path)
  end
end

#entries_for(directory) ⇒ Object



25
26
27
28
29
30
31
32
33
# File 'lib/stevenson/deployers/s3.rb', line 25

def entries_for(directory)
  if File.file?(directory)
    [
      [directory, File.basename(directory)]
    ]
  else
    Dir.glob("#{directory}/**/*").collect { |f| [f, f.partition(directory).last] }
  end
end