Sha256: e4c1bf53d358af9ed772b06b23b48fb8912f7b9e503db396dec12faf1a1f6740

Contents?: true

Size: 743 Bytes

Versions: 1

Compression:

Stored size: 743 Bytes

Contents

require 'yaml'

module Github
  class UserConfig
    # Do we actually need an instance here. Do we require state at any point?
    def initialize(file_path = File.expand_path('~') + '/.gistdoit')
      @file_path = file_path
    end

    def set_github_username(username)
      File.open(@file_path, 'a') do |file|
        file << YAML.dump({ 'github_username' => username })
      end
    end

    def has_github_username?
      YAML.load(File.readlines(@file_path).select { |line| !line.include?('---') }.join).key?('github_username')
    end

    def all
      file = File.read(@file_path)
      YAML.load(file)
    end

    def [](key)
      all[key]
    end

    def method_missing(symbol, *args)
      all[symbol.to_s]
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
gistdoit-0.0.1 lib/gistdoit/github/user_config.rb