Module: SyncFog

Defined in:
lib/sync_fog/version.rb,
lib/sync_fog.rb,
lib/sync_fog/configuration.rb,
lib/sync_fog/sync_fog_assets.rb,
lib/sync_fog/sync_fog_upload.rb,
lib/sync_fog/sync_fog_railtie.rb

Overview

SyncFog Gem github.com/ben-ole/sync_fog Benjamin Müller 2015

Defined Under Namespace

Classes: Configuration, InstallGenerator, SyncFogAssets, SyncFogRailtie, SyncFogUpload

Constant Summary collapse

VERSION =
"0.2.2"

Class Method Summary collapse

Class Method Details

.configurationObject



15
16
17
# File 'lib/sync_fog.rb', line 15

def self.configuration
  @configuration ||=  Configuration.new
end

.configure {|configuration| ... } ⇒ Object

Yields:



19
20
21
# File 'lib/sync_fog.rb', line 19

def self.configure
  yield(configuration) if block_given?
end

.public_urlObject



58
59
60
61
62
63
64
# File 'lib/sync_fog.rb', line 58

def self.public_url
  container_name = SyncFog.configuration.fog_directory

  fog_uploader = SyncFogUpload.new( container_name, SyncFog.configuration.fog_credentials )

  p "SyncFog: -- public url: #{fog_uploader.public_url}"    
end

.syncObject



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
53
54
55
56
# File 'lib/sync_fog.rb', line 23

def self.sync

  # check if hook is disabled
  return unless SyncFog.configuration.hook_enabled

  p "SyncFog: -- started syncing"

  container_name = SyncFog.configuration.fog_directory
  source_dir = SyncFog.configuration.source_dir

  p "SyncFog: -- source directory is: #{source_dir}"

  # check if target container exists
  fog_uploader = SyncFogUpload.new( container_name, SyncFog.configuration.fog_credentials )

  # list files to upload
  files = SyncFogAssets.new.list( source_dir )

  p "SyncFog: -- #{files.count} files found"

  # upload files
  p "SyncFog: -- uploading"
  root_path = Pathname.new File.expand_path('..',source_dir) # one dir up
  fog_uploader.upload( files, root_path )

  # delete old files
  p "SyncFog: -- cleaning up old files"
  fog_uploader.clean_remote( files )

  # info
  p "SyncFog: -- public url: #{fog_uploader.public_url}"

  p "SyncFog: -- done"
end