2012-09-01 23:39:28 -04:00
|
|
|
# Provides an ActiveRecord-like interface to a model whose data is not persisted to a database.
|
|
|
|
module StaticModel
|
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
|
|
|
module ClassMethods
|
|
|
|
# Used by ActiveRecord's polymorphic association to set object_id
|
|
|
|
def primary_key
|
|
|
|
'id'
|
|
|
|
end
|
|
|
|
|
|
|
|
# Used by ActiveRecord's polymorphic association to set object_type
|
|
|
|
def base_class
|
|
|
|
self
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# Used by AR for fetching attributes
|
|
|
|
#
|
|
|
|
# Pass it along if we respond to it.
|
|
|
|
def [](key)
|
|
|
|
send(key) if respond_to?(key)
|
|
|
|
end
|
|
|
|
|
|
|
|
def to_param
|
|
|
|
id
|
|
|
|
end
|
|
|
|
|
2012-09-17 10:06:56 -04:00
|
|
|
def new_record?
|
|
|
|
false
|
|
|
|
end
|
|
|
|
|
2012-09-01 23:39:28 -04:00
|
|
|
def persisted?
|
|
|
|
false
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroyed?
|
|
|
|
false
|
|
|
|
end
|
2012-10-13 10:23:12 -04:00
|
|
|
|
|
|
|
def ==(other)
|
|
|
|
if other.is_a? StaticModel
|
|
|
|
id == other.id
|
|
|
|
else
|
|
|
|
super
|
|
|
|
end
|
|
|
|
end
|
2012-09-01 23:39:28 -04:00
|
|
|
end
|