Class: Closync::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/closync/config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Config

Returns a new instance of Config.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/closync/config.rb', line 13

def initialize(opts={})
  self.credentials    = {}
  self.storage        = {}
  self.cache_control  = {}
  self.branch         = []

  @yml_path = ( opts[:yml_path] || "#{Dir.pwd}/.closync.yml" )

  if self.yml_exists?
    load_yml!
  else
    raise "Config file not found at #{opts[:yml_path]}" if opts[:yml_path]
  end
end

Instance Attribute Details

#branchObject

Git



10
11
12
# File 'lib/closync/config.rb', line 10

def branch
  @branch
end

#cache_controlObject

Returns the value of attribute cache_control.



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

def cache_control
  @cache_control
end

#credentialsObject

Fog config



5
6
7
# File 'lib/closync/config.rb', line 5

def credentials
  @credentials
end

#storageObject

Returns the value of attribute storage.



6
7
8
# File 'lib/closync/config.rb', line 6

def storage
  @storage
end

Instance Method Details

#localObject



45
46
47
# File 'lib/closync/config.rb', line 45

def local
  storage[:local] || (raise 'No local storage configured.')
end

#local=(config = {}) ⇒ Object



49
50
51
52
53
54
55
# File 'lib/closync/config.rb', line 49

def local=(config={})
  raise 'Config must include :provider and :directory.' unless
    config.keys == [:provider, :directory]
  storage[:local] = {}
  storage[:local][:provider] = config[:provider]
  storage[:local][:directory] = config[:directory]
end

#max_age(extension) ⇒ Object



36
37
38
39
# File 'lib/closync/config.rb', line 36

def max_age(extension)
  self.cache_control[extension] || self.cache_control['default'] ||
    (raise 'No default max-age configured.')
end

#remoteObject



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

def remote
  storage[:remote] || (raise 'No remote storage configured.')
end

#remote=(config = {}) ⇒ Object



61
62
63
64
65
66
67
# File 'lib/closync/config.rb', line 61

def remote=(config={})
  raise 'Config must include :provider and :directory.' unless
    config.keys == [:provider, :directory]
  storage[:remote] = {}
  storage[:remote][:provider] = config[:provider]
  storage[:remote][:directory] = config[:directory]
end

#set_max_age!(extension, max_age) ⇒ Object



41
42
43
# File 'lib/closync/config.rb', line 41

def set_max_age!(extension, max_age)
  self.cache_control[extension] = max_age
end

#yml_exists?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/closync/config.rb', line 32

def yml_exists?
  File.exists?(self.yml_path)
end

#yml_pathObject



28
29
30
# File 'lib/closync/config.rb', line 28

def yml_path
  @yml_path
end