diff options
| author | David Vazgenovich Shakaryan <dvshakaryan@gmail.com> | 2014-04-21 06:23:47 -0700 | 
|---|---|---|
| committer | David Vazgenovich Shakaryan <dvshakaryan@gmail.com> | 2014-04-21 06:23:47 -0700 | 
| commit | 607d7ae62d59bbc422da2211286fca96caa4f5e7 (patch) | |
| tree | 4aecaa05b0b4a995e1fbb3f7d8e7af2059cff80d /core | |
| parent | 349371e4c13e619b787fb4ab5a3dfcde95fd355e (diff) | |
| download | dinobot-607d7ae62d59bbc422da2211286fca96caa4f5e7.tar.gz dinobot-607d7ae62d59bbc422da2211286fca96caa4f5e7.tar.xz | |
Add config system for non-module data.
Diffstat (limited to 'core')
| -rw-r--r-- | core/config.rb | 43 | ||||
| -rw-r--r-- | core/store.rb | 2 | 
2 files changed, 44 insertions, 1 deletions
| diff --git a/core/config.rb b/core/config.rb new file mode 100644 index 0000000..fec2e18 --- /dev/null +++ b/core/config.rb @@ -0,0 +1,43 @@ +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[:data] + +        if @data.nil? +          @data = Hash.new + +          @data[:trigger] = Hash.new +          @data[:trigger][:global] = '!' + +          save +        end +      end + +      def save +        @store.data[:data] = @data +        @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 diff --git a/core/store.rb b/core/store.rb index 856acee..ba49733 100644 --- a/core/store.rb +++ b/core/store.rb @@ -11,7 +11,7 @@ module Dinobot          read -        @data ||= {} +        @data ||= Hash.new        end        def read | 
