Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
raidit/lib/entity.rb
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
40 lines (33 sloc)
708 Bytes
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
require 'active_model' | |
# Copied from ActiveModel::Model in Rails master HEAD | |
module Entity | |
def self.included(base) #:nodoc: | |
base.class_eval do | |
extend ActiveModel::Naming | |
include ActiveModel::Validations | |
include ActiveModel::Conversion | |
end | |
end | |
attr_accessor :id | |
def initialize(params={}) | |
params.each do |attr, value| | |
self.public_send("#{attr}=", value) | |
end if params | |
end | |
## | |
# From ActiveRecord::Base | |
## | |
def ==(other_entity) | |
super || | |
other_entity.instance_of?(self.class) && | |
id.present? && | |
other_entity.id == id | |
end | |
alias :eql? :== | |
## | |
# Required activemodel API calls | |
## | |
def persisted? | |
!!self.id | |
end | |
end |