Created
July 3, 2012 18:48
-
-
Save albus522/3041854 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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