Class: ActiveRecord::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/telasi-ruby/ext/active_record.rb

Direct Known Subclasses

Telasi::SAP::Base

Class Method Summary collapse

Class Method Details

.date_fields(*fields) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/telasi-ruby/ext/active_record.rb', line 5

def self.date_fields(*fields)
  fields.each do |field|
    define_method("#{field}_date") do
      date = send field.to_s
      Date.strptime(date, '%Y%m%d') if date
    end
    define_method("#{field}_date=") do |value|
      send( "#{field}=", value.strftime('%Y%m%d') ) if value
    end
  end
end