Sha256: 18694394110704fc7c866851dded78e60724d87af278a66b22032bd07ba3a46f

Contents?: true

Size: 1.08 KB

Versions: 1

Compression:

Stored size: 1.08 KB

Contents

module Secretmgr
  class Globalsetting
    require "yaml"
    require "pathname"

    def initialize(file_pn)
      @file_pn = file_pn
      @obj = nil
    end

    def ensure
      File.write(@file_pn, "") unless @file_pn.exist?
    end

    def load
      # p "@file_pn=#{@file_pn}"
      content = File.read(@file_pn)
      @obj = YAML.safe_load(content)
      @load ||= {}
      # p "Globalsetting.load @obj=#{@obj}|"
    end

    def save
      content = YAML.dump(@obj)
      File.write(@file_pn, content)
      p "Globalsetting.save @file_pn=#{@file_pn}|"
      p "Globalsetting.save content=#{content}|"
    end

    def get(key)
      case key
      when "default_public_keyfile_pn", "default_private_keyfile_pn"
        Pathname.new(@obj[key])
      else
        @obj[key]
      end
    end

    def set(key, value)
      @obj[key] = case key
                  when "default_public_keyfile_pn", "default_private_keyfile_pn"
                    value.to_s
                  # p "Globalsetting.set @obj=#{@obj}|"
                  else
                    value
                  end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
secretmgr-0.2.0 lib/secretmgr/globalsetting.rb