2013-03-13 122 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」)上的方法調用,給兩個參數。

希望這會有所幫助。