Class: Popper::Config
- Inherits:
-
Object
- Object
- Popper::Config
- Defined in:
- lib/popper/config.rb
Instance Attribute Summary collapse
-
#accounts ⇒ Object
readonly
Returns the value of attribute accounts.
-
#default ⇒ Object
readonly
Returns the value of attribute default.
-
#interval ⇒ Object
readonly
Returns the value of attribute interval.
Instance Method Summary collapse
-
#initialize(config_path) ⇒ Config
constructor
A new instance of Config.
- #read_file(file) ⇒ Object
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 |account| _account = AccountAttributes.new(account[1]) _account.name = account[0] _account end end |
Instance Attribute Details
#accounts ⇒ Object (readonly)
Returns the value of attribute accounts.
6 7 8 |
# File 'lib/popper/config.rb', line 6 def accounts @accounts end |
#default ⇒ Object (readonly)
Returns the value of attribute default.
6 7 8 |
# File 'lib/popper/config.rb', line 6 def default @default end |
#interval ⇒ Object (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 |