2013-03-13 125 views
0

我谟作品,其在开发红宝石在轨道上MVC模型在轨道上

我有这样一行:

_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是模型specialy中的一个函数:PMClient

账户的源代码是

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 

回答

0

我会认为你的问题是“这是什么代码怎么办?” (您可能需要在标题和问题文本中对其进行确定)。

_orig_account  = Account.find_ussd_by_login_and_pass_and_type_and_name(_orgin,_pin,Account::Type::Creova.to_sym,_orgin) 

没有任何其他信息,我会想:

  • 这是搜索和数据库返回的帐户查找方法。将模型中的类方法设为finder querie是Rails中非常标准的东西,其中许多提供了“开箱即用”。
  • 参数匹配各种“和”,起源是登录和名称(在这种情况下两者可能是相同的),然后是密码和类型(作为另一种Ruby常见做法Symbol给出) 。

第二部分:

_resul = PMClient.new.user_login_ussd(_orgin,_pin) 

简直是PMClient对象的创建(PMClient.new),立刻接着新创建的对象( “.user_login_ussd”)上的方法调用,给两个参数。

希望这会有所帮助。