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.



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

def initialize(opts={})
  self.credentials    = ( opts[:credentials]    || {} )
  self.storage        = ( opts[:storage]        || {} )
  self.cache_control  = ( opts[:cache_control]  || {} )
  self.branch         = ( opts[:branch]         || [] )
  self.working_dir    = ( opts[:working_dir]    || Dir.pwd)

  @yml_path = ( opts[:yml_path] || "#{self.working_dir}/.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



12
13
14
# File 'lib/closync/config.rb', line 12

def branch
  @branch
end

#cache_controlObject

Returns the value of attribute cache_control.



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

def cache_control
  @cache_control
end

#credentialsObject

Fog config



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

def credentials
  @credentials
end

#storageObject

Returns the value of attribute storage.



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

def storage
  @storage
end

#working_dirObject

Returns the value of attribute working_dir.



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

def working_dir
  @working_dir
end

Instance Method Details

#localObject



47
48
49
# File 'lib/closync/config.rb', line 47

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

#local=(config = {}) ⇒ Object



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

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



38
39
40
41
# File 'lib/closync/config.rb', line 38

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

#remoteObject



59
60
61
# File 'lib/closync/config.rb', line 59

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

#remote=(config = {}) ⇒ Object



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

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



43
44
45
# File 'lib/closync/config.rb', line 43

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

#yml_exists?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/closync/config.rb', line 34

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

#yml_pathObject



30
31
32
# File 'lib/closync/config.rb', line 30

def yml_path
  @yml_path
end