Class: Microstatic::Uploader

Inherits:
Object
  • Object
show all
Includes:
UsesFog
Defined in:
lib/microstatic/uploader.rb

Instance Method Summary collapse

Methods included from UsesFog

#check_and_store_aws_creds, #connection, #dns

Constructor Details

#initialize(base_dir, bucket, aws_creds) ⇒ Uploader

Returns a new instance of Uploader.



8
9
10
11
12
# File 'lib/microstatic/uploader.rb', line 8

def initialize( base_dir, bucket, aws_creds )
  check_and_store_aws_creds(aws_creds)
  @bucket = bucket
  @base_dir = Pathname.new(base_dir)
end

Instance Method Details

#upsert_filepath(filepath) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/microstatic/uploader.rb', line 14

def upsert_filepath( filepath )
  pathname = Pathname.new(filepath) 
  s3_key = relative_path_for(pathname)

  begin
    s3_object = connection.head_object(@bucket,s3_key)
  rescue Excon::Errors::NotFound
    log_action("NOT FOUND", s3_key)
    s3_object = false
  rescue Excon::Errors::Forbidden
    log_action("FORBIDDEN", s3_key)
    s3_object = false
  end


  if s3_object
    update_object_if_changed(s3_key, pathname,s3_object)
  else
    create_object(s3_key, pathname)
  end
end