Module: DocumentNumber::Model::ClassMethods
- Defined in:
- lib/document_number/has_document_number.rb
Instance Method Summary collapse
-
#get_numbers(quantity) ⇒ Object
Use this with your model to obtain an array of numbers.
-
#has_document_number(options = {}) ⇒ Object
Declare this in your model to automatic document number assignment.
Instance Method Details
#get_numbers(quantity) ⇒ Object
Use this with your model to obtain an array of numbers
Usage: numbers = Invoice.get_numbers(100)
46 47 48 49 50 51 52 |
# File 'lib/document_number/has_document_number.rb', line 46 def get_numbers(quantity) Array.new(Integer(quantity)) do "#{[:prefix]}#{Numerator.next_number(to_s.underscore, )}" end rescue [] end |
#has_document_number(options = {}) ⇒ Object
Declare this in your model to automatic document number assignment
Usage: class Invoice < ActiveRecord::Base
has_document_number
end
Options: :column the column name to update. Default value is :number. :prefix the prefix for number. :start the start value for number
Use params with_number to create an object with predefined number
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/document_number/has_document_number.rb', line 23 def has_document_number( = {}) .reverse_merge! :column => :number, :start => 1 class_attribute :document_number_options self. = .dup method_name = "auto_increment_#{[:column]}" before_create method_name after_initialize method_name, :if => Proc.new { with_number == true } define_method method_name do return if send([:column]).present? number = Numerator.next_number(self.class.to_s.underscore, ) prefix = [:prefix].present? ? [:prefix] : ::DocumentNumber.configuration.prefix write_attribute [:column], "#{prefix}#{number}" end end |