Sha256: 58ecfd842917408e7bc2186527ec6be36f7b0481d007cb86dab7cdd77e6078fa
Contents?: true
Size: 947 Bytes
Versions: 1
Compression:
Stored size: 947 Bytes
Contents
# encoding: utf-8 class Param include Mongoid::Document validates_uniqueness_of :code # Mindapp begin include Mongoid::Timestamps field :code, :type => String field :pid, :type => String field :yearly, :type => Boolean field :description, :type => String # Mindapp end def self.get(code) p= where(:code=> code).first p.pid end def self.set(code, pid) p= where(:code=> code).first p.pid = pid.to_s p.save end def self.gen(code) p= where(:code=> code).first unless p p= self.create! :code => code, :pid => '0', :yearly => false, :description => 'auto' end if p.yearly num, year = p.pid.split('/') y_now = (Time.now.year.to_i) -1957 if year.to_i==y_now p.pid = "#{num.to_i+1}/#{y_now}" else # new year, restart counter p.pid = "1/#{y_now}" end else p.pid = (p.pid.to_i+1).to_s end p.save return p.pid end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
mindapp-0.0.1 | lib/generators/mindapp/templates/app/models/param.rb |