mirror of
https://github.com/samsonjs/kwikemon.git
synced 2026-03-25 09:05:51 +00:00
support config file in Ruby client
This commit is contained in:
parent
7d398de64f
commit
9776c1cfef
5 changed files with 30 additions and 3 deletions
|
|
@ -1,3 +1,5 @@
|
|||
source 'https://rubygems.org'
|
||||
|
||||
gem 'hashie', '~> 2.0.5'
|
||||
gem 'redis', '~> 3.0.4'
|
||||
gem 'toml', '~> 0.0.4'
|
||||
|
|
|
|||
|
|
@ -1,10 +1,18 @@
|
|||
GEM
|
||||
remote: https://rubygems.org/
|
||||
specs:
|
||||
blankslate (2.1.2.4)
|
||||
hashie (2.0.5)
|
||||
parslet (1.5.0)
|
||||
blankslate (~> 2.0)
|
||||
redis (3.0.4)
|
||||
toml (0.0.4)
|
||||
parslet
|
||||
|
||||
PLATFORMS
|
||||
ruby
|
||||
|
||||
DEPENDENCIES
|
||||
hashie (~> 2.0.5)
|
||||
redis (~> 3.0.4)
|
||||
toml (~> 0.0.4)
|
||||
|
|
|
|||
|
|
@ -3,7 +3,9 @@
|
|||
# MIT License
|
||||
# http://sjs.mit-license.org
|
||||
|
||||
require 'hashie'
|
||||
require 'redis'
|
||||
require 'toml'
|
||||
require File.expand_path('../monitor.rb', __FILE__)
|
||||
|
||||
module Kwikemon
|
||||
|
|
@ -13,7 +15,7 @@ module Kwikemon
|
|||
include Enumerable
|
||||
|
||||
def redis
|
||||
@redis ||= Redis.new
|
||||
@redis ||= Redis.new(config.redis)
|
||||
end
|
||||
|
||||
def redis=(redis)
|
||||
|
|
@ -110,4 +112,19 @@ module Kwikemon
|
|||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def config
|
||||
@config ||= Hashie::Mash.new(load_config)
|
||||
end
|
||||
|
||||
def load_config
|
||||
path = File.join(ENV['HOME'], '.kwikemon.toml')
|
||||
if File.exists?(path)
|
||||
TOML.load_file(path)
|
||||
else
|
||||
{}
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -70,7 +70,7 @@ module Kwikemon
|
|||
end
|
||||
|
||||
def text
|
||||
@text ||= exists? ? redis.hget(key, 'name')
|
||||
@text ||= exists? ? redis.hget(key, 'name') : nil
|
||||
end
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,3 @@
|
|||
module Kwikemon
|
||||
VERSION = '0.0.1'
|
||||
VERSION = '0.0.2'
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in a new issue