Skip to content

Instantly share code, notes, and snippets.

@ptzn
Created November 24, 2010 01:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ptzn/712897 to your computer and use it in GitHub Desktop.
Save ptzn/712897 to your computer and use it in GitHub Desktop.
Using %SerialObject types
# %SerialObject types saved as string represents all object properties separated by commas,
# for example HM.TimeStampClass may look like "2004-04-16 03:20:07,BOB,2010-06-04 05:25:04,NJM,,117604"
# 1. Create a TimeStamp class that wrap %SerialObject
# Note the importance of the attributes declaration order, they will be mapped to string in this order
# Also you can override default mapping order via mapping method:
# def mapping
# [:attribute2, :attribute1, ...]
# end
class TimeStamp < Intersys::Serial::Object
attribute :create_date, :time
attribute :create_user
attribute :modify_date, :time
attribute :modify_user
attribute :create_revision
attribute :modify_revision
end
# 2. Add composed_of macro into Customer class
class Customer < ActiveRecord::Base
...
composed_of :ts, :class_name => 'TimeStamp'
end
# 3. Thats all:
c = Customer.find_by_cust_id('HMCB')
c.ts.create_user # => "BOB"
c.ts.create_date # => 2004-04-16 03:20:07 UTC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment