Class: Closync::Config
- Inherits:
-
Object
- Object
- Closync::Config
- Defined in:
- lib/closync/config.rb
Instance Attribute Summary collapse
-
#branch ⇒ Object
Git.
-
#cache_control ⇒ Object
Returns the value of attribute cache_control.
-
#credentials ⇒ Object
Fog config.
-
#storage ⇒ Object
Returns the value of attribute storage.
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ Config
constructor
A new instance of Config.
- #local ⇒ Object
- #local=(config = {}) ⇒ Object
- #max_age(extension) ⇒ Object
- #remote ⇒ Object
- #remote=(config = {}) ⇒ Object
- #set_max_age!(extension, max_age) ⇒ Object
- #yml_exists? ⇒ Boolean
- #yml_path ⇒ Object
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
#branch ⇒ Object
Git
10 11 12 |
# File 'lib/closync/config.rb', line 10 def branch @branch end |
#cache_control ⇒ Object
Returns the value of attribute cache_control.
7 8 9 |
# File 'lib/closync/config.rb', line 7 def cache_control @cache_control end |
#credentials ⇒ Object
Fog config
5 6 7 |
# File 'lib/closync/config.rb', line 5 def credentials @credentials end |
#storage ⇒ Object
Returns the value of attribute storage.
6 7 8 |
# File 'lib/closync/config.rb', line 6 def storage @storage end |
Instance Method Details
#local ⇒ Object
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 |
#remote ⇒ Object
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
32 33 34 |
# File 'lib/closync/config.rb', line 32 def yml_exists? File.exists?(self.yml_path) end |
#yml_path ⇒ Object
28 29 30 |
# File 'lib/closync/config.rb', line 28 def yml_path @yml_path end |