Created
January 26, 2011 20:15
-
-
Save frangucc/797353 to your computer and use it in GitHub Desktop.
Unpack Content Package
This file contains hidden or 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 Content_Package::Unpack | |
include ActiveModel::Serializers::JSON | |
include ActiveModel::Validations | |
ATTRIBUTES = [:test_id, :question_id, :answer] | |
attr_accessor *ATTRIBUTES | |
validates_presence_of :test_id, :question_id | |
validates_inclusion_of :answer, :in => %w[A B C D] | |
def initialize(attributes = {}) | |
self.attributes = attribute | |
end | |
def attributes | |
ATTRIBUTES.inject( | |
ActiveSupport::HashWithIndifferentAccess.new | |
) do |result, key| | |
result[key] = read_attribute_for_validation(key) | |
result | |
end | |
end | |
def attributes=(attrs) | |
attrs.each_pair {|k, v| send("#{k}=", v)} | |
end | |
def read_attribute_for_validation(key) | |
send(key) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment