Class: DevArchive::Cfg

Inherits:
Object
  • Object
show all
Defined in:
lib/dev_archive/cfg.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCfg

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_storesObject

Returns the value of attribute active_stores.



47
48
49
# File 'lib/dev_archive/cfg.rb', line 47

def active_stores
  @active_stores
end

#pwdObject

Returns the value of attribute pwd.



47
48
49
# File 'lib/dev_archive/cfg.rb', line 47

def pwd
  @pwd
end

#storage_pathObject

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

.instanceObject



36
37
38
# File 'lib/dev_archive/cfg.rb', line 36

def instance
  @instance ||= Cfg.new
end

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

#repositoryObject



76
77
78
# File 'lib/dev_archive/cfg.rb', line 76

def repository
  Repositories::FileSystem.new(path: storage_path)
end

#shellObject



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

#storesObject



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