aboutsummaryrefslogtreecommitdiff
path: root/core/config.rb
blob: 466e435feb158855f6b72dfff61fdd4d4550aa3d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
require_relative 'store'

module Dinobot
  module Core
    class Config
      attr_accessor :data

      @@instance = nil
      @@mutex = Mutex.new

      def initialize
        @store = Dinobot::Core::Store.new('config')
        @data = @store.data

        if @data.empty?
          @data[:debug] = false
          @data[:trigger] = {global: '!'}

          save
        end
      end

      def save
        @store.save
      end

      class << self
        def instance
          return @@instance if @@instance

          @@mutex.synchronize do
            @@instance ||= new
          end
        end
      end

      private_class_method :allocate, :new
    end
  end
end