Class: CrossPost::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/cross-post/config.rb

Defined Under Namespace

Classes: FifoSubConfig, FileSubConfig, SubConfig

Constant Summary collapse

DEFAULT_CONFIG_FOLDER =
File.join Dir.home, '.config/cross-post'
DEFAULT_CONFIG_FILE =
'config.yml'

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



96
97
98
99
100
101
102
103
# File 'lib/cross-post/config.rb', line 96

def initialize
  @configs = {}
  @dir     = ENV.fetch 'CONFIG_FOLDER', DEFAULT_CONFIG_FOLDER
  file     = ENV.fetch 'CONFIG_FILE', DEFAULT_CONFIG_FILE
  self.load :settings, file
  self.load :users
  self[:posts] = FifoSubConfig.new
end

Instance Method Details

#[](name) ⇒ Object



105
106
107
# File 'lib/cross-post/config.rb', line 105

def [](name)
  @configs[name]
end

#[]=(name, value) ⇒ Object



109
110
111
# File 'lib/cross-post/config.rb', line 109

def []=(name, value)
  @configs[name] = value
end

#load(name, file = nil) ⇒ Object



113
114
115
116
117
118
# File 'lib/cross-post/config.rb', line 113

def load(name, file = nil)
  file ||= "#{name}.yml"
  file = File.join @dir, file
  File.write(file, YAML.dump({})) unless File.exist? file
  self[name] = FileSubConfig.new file
end