Class: DevArchive::Cfg
- Inherits:
-
Object
- Object
- DevArchive::Cfg
- Defined in:
- lib/dev_archive/cfg.rb
Instance Attribute Summary collapse
-
#active_stores ⇒ Object
Returns the value of attribute active_stores.
-
#pwd ⇒ Object
Returns the value of attribute pwd.
-
#storage_path ⇒ Object
Returns the value of attribute storage_path.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize ⇒ Cfg
constructor
A new instance of Cfg.
- #load(path = ".config/dev_archive.rb") ⇒ Object
- #register_store(name, klass = nil, active_by_default: true, &block) ⇒ Object
- #repository ⇒ Object
- #shell ⇒ Object
- #store(name) ⇒ Object
- #stores ⇒ Object
Constructor Details
#initialize ⇒ Cfg
Returns a new instance of Cfg.
48 49 50 |
# File 'lib/dev_archive/cfg.rb', line 48 def initialize self.active_stores = [] end |
Instance Attribute Details
#active_stores ⇒ Object
Returns the value of attribute active_stores.
47 48 49 |
# File 'lib/dev_archive/cfg.rb', line 47 def active_stores @active_stores end |
#pwd ⇒ Object
Returns the value of attribute pwd.
47 48 49 |
# File 'lib/dev_archive/cfg.rb', line 47 def pwd @pwd end |
#storage_path ⇒ Object
Returns the value of attribute storage_path.
47 48 49 |
# File 'lib/dev_archive/cfg.rb', line 47 def storage_path @storage_path end |
Class Method Details
Instance Method Details
#load(path = ".config/dev_archive.rb") ⇒ Object
52 53 54 55 56 57 |
# File 'lib/dev_archive/cfg.rb', line 52 def load(path = ".config/dev_archive.rb") config_path = File.join(ENV["HOME"], path) require("dev_archive/default_configuration") Kernel.load(config_path) if File.exist?(config_path) end |
#register_store(name, klass = nil, active_by_default: true, &block) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/dev_archive/cfg.rb', line 59 def register_store(name, klass=nil, active_by_default: true, &block) store = ( if klass klass else builder = StoreBuilder.new yield(builder) builder.to_store end ) store_registry[name] = store if active_by_default active_stores << name end end |
#repository ⇒ Object
76 77 78 |
# File 'lib/dev_archive/cfg.rb', line 76 def repository Repositories::FileSystem.new(path: storage_path) end |
#shell ⇒ Object
94 95 96 |
# File 'lib/dev_archive/cfg.rb', line 94 def shell @shell ||= Shell.new end |
#store(name) ⇒ Object
80 81 82 |
# File 'lib/dev_archive/cfg.rb', line 80 def store(name) store_registry.fetch(name) end |
#stores ⇒ Object
84 85 86 87 88 89 90 91 92 |
# File 'lib/dev_archive/cfg.rb', line 84 def stores unknown_keys = active_stores - store_registry.keys if !unknown_keys.empty? raise ArgumentError.new("invalid store(s): #{unknown_keys.join(",")}") end store_registry.slice(*active_stores) end |