Class: S3Deployer
- Inherits:
-
Object
- Object
- S3Deployer
- Defined in:
- lib/s3deployer.rb,
lib/s3deployer/version.rb
Constant Summary collapse
- VERSION =
"0.0.5"
Instance Attribute Summary collapse
-
#bucket_name ⇒ Object
Returns the value of attribute bucket_name.
-
#directory_to_deploy ⇒ Object
Returns the value of attribute directory_to_deploy.
Instance Method Summary collapse
- #deploy(directory_to_deploy, bucket_name) ⇒ Object
-
#initialize(access_key, secret_key) ⇒ S3Deployer
constructor
A new instance of S3Deployer.
- #iterate_through_and_deploy(dir) ⇒ Object
- #upload_item(item) ⇒ Object
Constructor Details
#initialize(access_key, secret_key) ⇒ S3Deployer
Returns a new instance of S3Deployer.
6 7 8 9 10 |
# File 'lib/s3deployer.rb', line 6 def initialize(access_key, secret_key) AWS::S3::Base.establish_connection!({ :access_key_id => access_key, :secret_access_key => secret_key}) end |
Instance Attribute Details
#bucket_name ⇒ Object
Returns the value of attribute bucket_name.
5 6 7 |
# File 'lib/s3deployer.rb', line 5 def bucket_name @bucket_name end |
#directory_to_deploy ⇒ Object
Returns the value of attribute directory_to_deploy.
5 6 7 |
# File 'lib/s3deployer.rb', line 5 def directory_to_deploy @directory_to_deploy end |
Instance Method Details
#deploy(directory_to_deploy, bucket_name) ⇒ Object
11 12 13 14 15 |
# File 'lib/s3deployer.rb', line 11 def deploy(directory_to_deploy, bucket_name) @bucket_name = bucket_name @directory_to_deploy = File.(directory_to_deploy) iterate_through_and_deploy(directory_to_deploy) end |
#iterate_through_and_deploy(dir) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/s3deployer.rb', line 17 def iterate_through_and_deploy(dir) Dir.foreach(dir) do |item| next if item[0] == "." item_location = "#{dir}/#{item}" if File.directory?(item_location) iterate_through_and_deploy(item_location) else upload_item(item_location) end end end |
#upload_item(item) ⇒ Object
29 30 31 32 33 34 |
# File 'lib/s3deployer.rb', line 29 def upload_item(item) item_as_path = Pathname.new(item) s3_name = item_as_path.sub("#{@directory_to_deploy}/", '').cleanpath.to_s puts "uploading #{item} as #{s3_name}" AWS::S3::S3Object.store(s3_name, open(item), bucket_name) end |