Module: Wechat
- Defined in:
- lib/wechat/config.rb,
lib/wechat/access_token.rb,
lib/wechat/access_token/railtie.rb,
lib/wechat/access_token/version.rb
Defined Under Namespace
Modules: AccessToken
Class Method Summary collapse
Class Method Details
.clear_config ⇒ Object
46 47 48 |
# File 'lib/wechat/config.rb', line 46 def self.clear_config @config = nil end |
.clear_redis ⇒ Object
42 43 44 |
# File 'lib/wechat/config.rb', line 42 def self.clear_redis @redis = nil end |
.config ⇒ Object
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/wechat/config.rb', line 2 def self.config @config ||= begin path = ::Rails.root.join("config/wechat.yml") raise StandardError, '请先在config文件夹下配置wechat.yml' unless File.exists?(path) result = YAML::load(ERB.new(IO.read(path)).result) rescue {} result = Hashie::Mash.new(result) if result.base.nil? || result.base.appid.nil? || result.base.appsecret.nil? raise StandardError, "wechat.yml文件配置错误" end result end end |
.redis ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/wechat/config.rb', line 20 def self.redis @redis ||= begin path = ::Rails.root.join("config/redis.yml") raise StandardError, '请先在config文件夹下配置redis.yml' unless File.exists?(path) result = YAML::load(ERB.new(IO.read(path)).result) #rescue {} result = result[Rails.env] raise StandardError, "redis.yml文件配置错误" if result.nil? result = Hashie::Mash.new(result) if result.host.nil? || result.port.nil? || result.wechat_db.nil? raise StandardError, "redis.yml文件配置错误" end Redis.new(host: result.host, password: result.password, port: result.port, db: result.wechat_db) end end |