Module: AssetSync

Defined in:
lib/asset_sync/config.rb,
lib/asset_sync/engine.rb,
lib/asset_sync/storage.rb,
lib/asset_sync/version.rb,
lib/asset_sync/asset_sync.rb,
lib/asset_sync/multi_mime.rb,
lib/generators/asset_sync/install_generator.rb

Defined Under Namespace

Classes: Config, Engine, InstallGenerator, MultiMime, Storage

Constant Summary collapse

VERSION =
"2.19.2"

Class Method Summary collapse

Class Method Details

.cleanObject



35
36
37
38
39
# File 'lib/asset_sync/asset_sync.rb', line 35

def clean
  with_config do
    self.storage.delete_extra_remote_files
  end
end

.configObject



11
12
13
14
# File 'lib/asset_sync/asset_sync.rb', line 11

def config
  @config ||= Config.new
  @config
end

.config=(data) ⇒ Object



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

def config=(data)
  @config = data
end

.configure {|@config| ... } ⇒ Object

Yields:



20
21
22
23
# File 'lib/asset_sync/asset_sync.rb', line 20

def configure(&proc)
  @config ||= Config.new
  yield @config
end

.enabled?Boolean

Returns:

  • (Boolean)


73
74
75
# File 'lib/asset_sync/asset_sync.rb', line 73

def enabled?
  config.enabled?
end

.load_yaml(yaml) ⇒ Object



65
66
67
68
69
70
71
# File 'lib/asset_sync/asset_sync.rb', line 65

def load_yaml(yaml)
  if YAML.respond_to?(:unsafe_load)
    YAML.unsafe_load(yaml)
  else
    YAML.load(yaml)
  end
end

.log(msg) ⇒ Object



61
62
63
# File 'lib/asset_sync/asset_sync.rb', line 61

def log(msg)
  stdout.puts msg unless config.log_silently?
end

.reset_config!Object



16
17
18
# File 'lib/asset_sync/asset_sync.rb', line 16

def reset_config!
  remove_instance_variable :@config if defined?(@config)
end

.stderrObject

easier to stub



78
# File 'lib/asset_sync/asset_sync.rb', line 78

def stderr ; STDERR ; end

.stdoutObject



79
# File 'lib/asset_sync/asset_sync.rb', line 79

def stdout ; STDOUT ; end

.storageObject



25
26
27
# File 'lib/asset_sync/asset_sync.rb', line 25

def storage
  @storage ||= Storage.new(self.config)
end

.syncObject



29
30
31
32
33
# File 'lib/asset_sync/asset_sync.rb', line 29

def sync
  with_config do
    self.storage.sync
  end
end

.warn(msg) ⇒ Object



57
58
59
# File 'lib/asset_sync/asset_sync.rb', line 57

def warn(msg)
  stderr.puts msg
end

.with_config(&block) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/asset_sync/asset_sync.rb', line 41

def with_config(&block)
  return unless AssetSync.enabled?

  errors = config.valid? ? "" : config.errors.full_messages.join(', ')

  if !(config && config.valid?)
    if config.fail_silently?
      self.warn(errors)
    else
      raise Config::Invalid.new(errors)
    end
  else
    block.call
  end
end