Module: Versionable::ClassMethods
- Defined in:
- lib/versionable.rb
Instance Method Summary collapse
-
#new_version ⇒ Object
Sets the version of this assocation to the current time in integer form.
-
#object ⇒ Object
Returns the object that version applies to.
-
#version ⇒ Object
Returns the current version of the assocation.
-
#version_cache_key ⇒ Object
Returns the association version key.
-
#version_name ⇒ Object
Returns the name portion of the version cache key.
Instance Method Details
#new_version ⇒ Object
Sets the version of this assocation to the current time in integer form.
33 34 35 36 37 38 39 |
# File 'lib/versionable.rb', line 33 def new_version # the expiry needs to be longer than any page that might use this as a # cache key. time = Time.now.to_i [:cache].write(version_cache_key, time, :expires_in => [:ttl]) time end |
#object ⇒ Object
Returns the object that version applies to.
55 56 57 58 59 60 61 |
# File 'lib/versionable.rb', line 55 def object if inside_association? proxy_owner else self end end |
#version ⇒ Object
Returns the current version of the assocation. Likely to be nil.
28 29 30 |
# File 'lib/versionable.rb', line 28 def version [:cache].read(version_cache_key) end |
#version_cache_key ⇒ Object
Returns the association version key.
42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/versionable.rb', line 42 def version_cache_key parts = if object.class == Class [object] else [object.class, object.id] end parts << version_name parts * ':' end |
#version_name ⇒ Object
Returns the name portion of the version cache key
64 65 66 67 68 69 70 |
# File 'lib/versionable.rb', line 64 def version_name if inside_association? "#{proxy_reflection.name}_version" else "version" end end |