mirror of
https://github.com/samsonjs/kwikemon.git
synced 2026-04-27 15:07:45 +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'
|
source 'https://rubygems.org'
|
||||||
|
|
||||||
|
gem 'hashie', '~> 2.0.5'
|
||||||
gem 'redis', '~> 3.0.4'
|
gem 'redis', '~> 3.0.4'
|
||||||
|
gem 'toml', '~> 0.0.4'
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,18 @@
|
||||||
GEM
|
GEM
|
||||||
remote: https://rubygems.org/
|
remote: https://rubygems.org/
|
||||||
specs:
|
specs:
|
||||||
|
blankslate (2.1.2.4)
|
||||||
|
hashie (2.0.5)
|
||||||
|
parslet (1.5.0)
|
||||||
|
blankslate (~> 2.0)
|
||||||
redis (3.0.4)
|
redis (3.0.4)
|
||||||
|
toml (0.0.4)
|
||||||
|
parslet
|
||||||
|
|
||||||
PLATFORMS
|
PLATFORMS
|
||||||
ruby
|
ruby
|
||||||
|
|
||||||
DEPENDENCIES
|
DEPENDENCIES
|
||||||
|
hashie (~> 2.0.5)
|
||||||
redis (~> 3.0.4)
|
redis (~> 3.0.4)
|
||||||
|
toml (~> 0.0.4)
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,9 @@
|
||||||
# MIT License
|
# MIT License
|
||||||
# http://sjs.mit-license.org
|
# http://sjs.mit-license.org
|
||||||
|
|
||||||
|
require 'hashie'
|
||||||
require 'redis'
|
require 'redis'
|
||||||
|
require 'toml'
|
||||||
require File.expand_path('../monitor.rb', __FILE__)
|
require File.expand_path('../monitor.rb', __FILE__)
|
||||||
|
|
||||||
module Kwikemon
|
module Kwikemon
|
||||||
|
|
@ -13,7 +15,7 @@ module Kwikemon
|
||||||
include Enumerable
|
include Enumerable
|
||||||
|
|
||||||
def redis
|
def redis
|
||||||
@redis ||= Redis.new
|
@redis ||= Redis.new(config.redis)
|
||||||
end
|
end
|
||||||
|
|
||||||
def redis=(redis)
|
def redis=(redis)
|
||||||
|
|
@ -110,4 +112,19 @@ module Kwikemon
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
|
|
|
||||||
|
|
@ -70,7 +70,7 @@ module Kwikemon
|
||||||
end
|
end
|
||||||
|
|
||||||
def text
|
def text
|
||||||
@text ||= exists? ? redis.hget(key, 'name')
|
@text ||= exists? ? redis.hget(key, 'name') : nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,3 @@
|
||||||
module Kwikemon
|
module Kwikemon
|
||||||
VERSION = '0.0.1'
|
VERSION = '0.0.2'
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue