class WechatConfig

Used by wechat gems, do not rename WechatConfig to other name, Feel free to inherit from other class like ActiveModel::Model

Constants

ATTRIBUTES_TO_REMOVE

Public Class Methods

get_all_configs(environment) click to toggle source
# File lib/generators/wechat/templates/app/models/wechat_config.rb, line 17
def self.get_all_configs(environment)
  WechatConfig.where(environment: environment, enabled: true).each_with_object({}) do |config, hash|
    hash[config.account] = config.build_config_hash
  end
end

Public Instance Methods

build_config_hash() click to toggle source
# File lib/generators/wechat/templates/app/models/wechat_config.rb, line 23
def build_config_hash
  as_json(except: ATTRIBUTES_TO_REMOVE)
end

Private Instance Methods

app_config_is_valid() click to toggle source
# File lib/generators/wechat/templates/app/models/wechat_config.rb, line 29
def app_config_is_valid
  if self[:appid].present?
    # public account
    errors.add(:secret, 'cannot be nil when appid is set') if self[:secret].blank?
  elsif self[:corpid].present?
    # corp account
    errors.add(:corpsecret, 'cannot be nil when corpid is set') if self[:corpsecret].blank?
    errors.add(:agentid, 'cannot be nil when corpid is set') if self[:agentid].blank?
  else
    errors.add(:base, 'Either appid or corpid must be set')
  end
end