Class: Popper::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/popper/config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config_path) ⇒ Config

Returns a new instance of Config.



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/popper/config.rb', line 7

def initialize(config_path)
  raise "configure not fond #{config_path}" unless File.exist?(config_path)
  config = read_file(config_path)

  @interval = config.key?("interval") ? config["interval"].to_i : 60
  @default = config["default"] if config["default"]
  @accounts = config.select {|k,v| v.is_a?(Hash) && v.key?("login") }.map do ||
     = AccountAttributes.new([1])
    .name = [0]
    
  end
end

Instance Attribute Details

#accountsObject (readonly)

Returns the value of attribute accounts.



6
7
8
# File 'lib/popper/config.rb', line 6

def accounts
  @accounts
end

#defaultObject (readonly)

Returns the value of attribute default.



6
7
8
# File 'lib/popper/config.rb', line 6

def default
  @default
end

#intervalObject (readonly)

Returns the value of attribute interval.



6
7
8
# File 'lib/popper/config.rb', line 6

def interval
  @interval
end

Instance Method Details

#read_file(file) ⇒ Object



20
21
22
23
24
25
26
27
# File 'lib/popper/config.rb', line 20

def read_file(file)
  config = TOML.load_file(file)
  if config.key?("include")
    content = config["include"].map {|p| Dir.glob(p).map {|f|File.read(f)}}.join("\n")
    config.deep_merge!(TOML::Parser.new(content).parsed)
  end
  config
end