lib/protokoll/protokoll.rb
# Class method available in models
#
# == Example
#   class Order < ActiveRecord::Base
#      protokoll :number
#   end
#
Class method available in models
Example
class Order < ActiveRecord::Base
protokoll :number
end
Class method available in models Example class Order < ActiveRecord :: Base protokoll : number end
def protokoll(column, _options = {})
      options = { :pattern       => "%Y%m#####",
                  :number_symbol => "#",
                  :column        => column,
                  :start         => 0,
                  :scope_by      => nil }
      options.merge!(_options)
      raise ArgumentError.new("pattern can't be nil!") if options[:pattern].nil?
      raise ArgumentError.new("pattern requires at least one counter symbol #{options[:number_symbol]}") unless pattern_includes_symbols?(options)
      send :define_method, "reserve_#{options[:column]}!".to_sym do
        self[column] = Counter.next(self, options)
      end
      before_create do |record|
        unless record[column].present?
          record[column] = Counter.next(self, options)
        end
      end
    end
def protokoll ( column , _options = { } ) options = { :pattern => "%Y%m#####" , :number_symbol => "#" , :column => column , :start => 0 , :scope_by => nil } options . merge! ( _options ) raise ArgumentError . new ( "pattern can't be nil!" ) if options [ :pattern ] . nil? raise ArgumentError . new ( "pattern requires at least one counter symbol #{options[:number_symbol]}" ) unless pattern_includes_symbols? ( options ) send :define_method , "reserve_#{options[:column]}!" . to_sym do self [ column ] = Counter . next ( self , options ) end before_create do | record | unless record [ column ] . present? record [ column ] = Counter . next ( self , options ) end end end
Class method available in models
 Example
class Order < ActiveRecord::Base
protokoll :number
end
Class method available in models Example class Order < ActiveRecord :: Base protokoll : number end
# Defining custom method # Signing before_create
column
<not_specific>
_options
<not_specific>