Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Delegate #to_key to #key_factory.

Allows key factories to return to_key values that are usable with rails
when they do not to_s in a pretty fashion.
  • Loading branch information...
commit 3cb3dfedbeb477b41a0a925a0142b3bbeb1b0c5b 1 parent 4960cd5
@jnunemaker authored
Showing with 8 additions and 0 deletions.
  1. +4 −0 lib/toy/identity/abstract_key_factory.rb
  2. +4 −0 lib/toy/object.rb
View
4 lib/toy/identity/abstract_key_factory.rb
@@ -9,6 +9,10 @@ def next_key(object)
raise NotImplementedError, "#{self.class.name}#next_key isn't implemented."
end
+ def to_key(object)
+ [object.id] if object.persisted?
+ end
+
def eql?(other)
self.class == other.class && key_type == other.key_type
end
View
4 lib/toy/object.rb
@@ -17,5 +17,9 @@ module Object
def persisted?
false
end
+
+ def to_key
+ key_factory.to_key(self)
+ end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.