Module: Protokoll::ClassMethods
- Defined in:
- lib/protokoll/protokoll.rb
Instance Method Summary collapse
-
#protokoll(column, _options = {}) ⇒ Object
Class method available in models.
Instance Method Details
#protokoll(column, _options = {}) ⇒ Object
Class method available in models
Example
class Order < ActiveRecord::Base
protokoll :number
end
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/protokoll/protokoll.rb', line 13 def protokoll(column, = {}) = { :pattern => "%Y%m#####", :number_symbol => "#", :column => column, :start => 0 } .merge!() raise ArgumentError.new("pattern can't be nil!") if [:pattern].nil? raise ArgumentError.new("pattern requires at least one counter symbol #{options[:number_symbol]}") unless pattern_includes_symbols?() # Defining custom method send :define_method, "reserve_#{options[:column]}!".to_sym do self[column] = Counter.next(self, ) end # Signing before_create before_create do |record| unless record[column].present? record[column] = Counter.next(self, ) end end end |