我在用 ruby on rails 开发的 projet 工作
我有这条线:
_orig_account = Account.find_ussd_by_login_and_pass_and_type_and_name(_orgin,_pin,Account::Type::Creova.to_sym,_orgin)
老实说,我不明白这段代码
我有另一个代码:
_resul = PMClient.new.user_login_ussd(_orgin,_pin)
在这种情况下,user_login_ussd 是模型中的一个函数,专门用于:PMClient
Account的源代码是
class Account < CreovaBase
attr :login, true
attr :admin_login, true
attr :admin_pass, true
attr :type
attr :name, true
attr :status
attr :balance, true
attr :currency
attr :dob, true
attr :bank_id, true
attr :routing, true
attr :legal_name, true
attr :bank_name, true
attr :attribute, true
attr :linker_id, true
Status = Enum.new(:Enabled, :Suspended,:Deleted, :Legal_Hold, ['Enabled','Suspended','Deleted','Legal Hold'])
Type = Enum.new(:Creova, :Bank, :Credit,:rt, ['Creova','Bank','Credit','rt'])
Banks = Enum.new(:None, :Test1,:Test2 , :Test3, :Test4,
['','Test1','Test2','Test3','Test4'])
def initialize(params=nil)
super
end
def type=(val)
val.blank? ? @type = nil : @type = val.to_sym
end
def status=(val)
val.blank? ? @status = nil : @status = val.to_sym
end
def currency=(val)
val.blank? ? @currency = nil : @currency = val.to_sym
end
# should check that the account number either:
# a) exists in the system
# b) is a valid mobile number
# c) ?? is a valid email address ??
# returns [valid,message]
def self.is_valid_account?(name, purpose=:send)
#STUB
return true
end
def formatted_balance(currency = :tnd)
curr = Currency.get_currency(currency) rescue Currency.get_currency(:tnd)
curr.display(balance.to_i)
end
def formal_name(currency=:tnd)
curr = Currency.get_currency(currency) rescue Currency.get_currency(:tnd)
curr.formal_name
end
def save!
#pmac = CreovaBase._get_admin()
if @new_record
# create_account will raise an exception if it cannot be created
vars = self.instance_variables.map() { |v| v.sub('@','') unless ['@errors','@new_record'].include?(v) }.compact
params = {}
vars.each() do |v|
if self.send(v).is_a?(Enum::Member)
params[v] = self.send(v).to_sym
else
params[v] = self.send(v)
end
end
if PMClient.new.create_account(params)
@new_record = false
else
raise 'account save failed'
end
else
PMClient.new.update_account(admin_login,admin_pass,type,name,status)
end
end
def save
save!
end
end