Skip to content

Instantly share code, notes, and snippets.

@albus522
Created July 3, 2012 18:48
Show Gist options
  • Save albus522/3041854 to your computer and use it in GitHub Desktop.
Save albus522/3041854 to your computer and use it in GitHub Desktop.
class Message
include ActiveModel::Conversion
include ActiveModel::Validations
extend ActiveModel::Naming
attr_reader :attributes
def initialize(attributes = {})
@attributes = attributes
# TODO
#
# Define setter and getter methods for each attribute.
#
# message = Message.new(:foo => 'bar')
# message.foo # => 'bar'
# message.attributes[:foo] # => 'bar'
# message.foo = 'baz'
# message.foo # => 'baz'
# message.attributes[:foo] # => 'baz'
#
@attributes.each_key do |key|
eval <<-EOS
def self.#{key}
@attributes[#{key.inspect}]
end
def self.#{key}=(val)
@attributes[#{key.inspect}] = val
end
EOS
end
end
def persisted?
false
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment