Sha256: 65340509506c99590963e799832f2eeb0584825607997f2e253c32945bd64315

Contents?: true

Size: 1.33 KB

Versions: 52

Compression:

Stored size: 1.33 KB

Contents

# -*- coding: utf-8 -*-
#
# Copyright 2013 whiteleaf. All rights reserved.
#

require "yaml"
require "singleton"

#
# 管理小説のみに適用される設定
#
class LocalSetting
  include Singleton

  def self.get
    instance
  end

  def initialize
    @local_settings = load_settings
  end

  def [](name)
    setting = @local_settings[name]
    unless setting
      setting = {}
      @local_settings[name] = setting
    end
    setting
  end

  def []=(name, setting)
    @local_settings[name] = setting
  end

  def save_settings(name = nil)
    if name
      save_list = { name => @local_settings[name] }
    else
      save_list = @local_settings
    end
    save_list.each do |sname, setting|
      path = File.join(Narou.get_local_setting_dir, sname + ".yaml")
      File.write(path, YAML.dump(setting))
    end
  end

  #
  # .narou 以下に保存されている *.yaml の拡張子を取った部分をキーとして
  # 設定をハッシュとして取得する
  #
  def load_settings
    settings = {}
    local_setting_dir = Narou.get_local_setting_dir
    if local_setting_dir
      Dir.glob(File.join(local_setting_dir, "*.yaml")) do |path|
        name = File.basename(path, ".yaml")
        settings[name] = YAML.load_file(path)
      end
    end
    settings
  end
end

Version data entries

52 entries across 52 versions & 1 rubygems

Version Path
narou-1.5.11 lib/localsetting.rb
narou-1.5.10.1 lib/localsetting.rb
narou-1.5.10 lib/localsetting.rb
narou-1.5.9 lib/localsetting.rb
narou-1.5.8 lib/localsetting.rb
narou-1.5.7.1 lib/localsetting.rb
narou-1.5.7 lib/localsetting.rb
narou-1.5.6.1 lib/localsetting.rb
narou-1.5.6 lib/localsetting.rb
narou-1.5.5.1 lib/localsetting.rb
narou-1.5.5 lib/localsetting.rb
narou-1.5.4 lib/localsetting.rb
narou-1.5.3 lib/localsetting.rb
narou-1.5.2.1 lib/localsetting.rb
narou-1.5.2 lib/localsetting.rb
narou-1.5.1 lib/localsetting.rb
narou-1.5.0.2 lib/localsetting.rb
narou-1.5.0.1 lib/localsetting.rb
narou-1.5.0 lib/localsetting.rb
narou-1.4.6 lib/localsetting.rb