Skip to content

Commit

Permalink
Delegate #to_key to #key_factory.
Browse files Browse the repository at this point in the history
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
jnunemaker committed Nov 16, 2012
1 parent 4960cd5 commit 3cb3dfe
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/toy/identity/abstract_key_factory.rb
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions lib/toy/object.rb
Expand Up @@ -17,5 +17,9 @@ module Object
def persisted?
false
end

def to_key
key_factory.to_key(self)
end
end
end

0 comments on commit 3cb3dfe

Please sign in to comment.