<commit_before>require 'yaml/store'

module TddiumStatus
  class Configuration
    def initialize(path = self.class.default_path)
      @store = YAML::Store.new(path)
    end

    def feeds
      @feeds ||= @store.transaction do
        @store[:feeds] ||= []
      end
    end

    def feeds=(feeds)
      @store.transaction do
        @store[:feeds] = feeds || []
      end
    end

    def save_feed(feed)
      feeds = self.feeds
      feeds << feed unless feeds.include?(feed)
      self.feeds = feeds
    end

    def self.default_path
      File.join(Dir.home, '.tddium_status.yml')
    end
  end
end<commit_msg>YAML::Store does not work on MacRuby<commit_after>require 'yaml'

module TddiumStatus
  class Configuration
    def initialize(path = self.class.default_path)
      @path = path
      @lock = Mutex.new
    end

    def feeds
      @feeds ||= transaction do |data|
        data[:feeds] ||= []
      end
    end

    def feeds=(feeds)
      transaction do |data|
        data[:feeds] = feeds || []
      end
    end

    def save_feed(feed)
      feeds = self.feeds
      feeds << feed unless feeds.include?(feed)
      self.feeds = feeds
    end

    def transaction(&block)
      @lock.synchronize do
        data = YAML.load(File.read(@path)) rescue {}
        result = block.call(data)
        File.open(@path, "w") do |f|
          f.write(YAML.dump(data))
        end
        result
      end
    end

    def self.default_path
      File.join(Dir.home, '.tddium_status.yml')
    end
  end
end
{'fraction_non_alphanumeric': 0.11155115511551156, 'fraction_numerical': 0.0, 'mean_word_length': 2.0875763747454177, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4992112', 'n_tokens_mistral': 517, 'n_tokens_neox': 491, 'n_words': 118}