Module: Glue::Revisable
- Defined in:
- lib/glue/revisable.rb
Overview
Revision support for Og-managed classes.
class Article
is Revisable
property :body, String, :revisable => true
property :title, String
end
Generates the Revision class:
class Article::Revision
article.revisions
article.revise do |a|
a.title = 'hello'
a.body = 'world'
end
article.rollback(4)
Defined Under Namespace
Modules: Mixin
Class Method Summary collapse
Instance Method Summary collapse
-
#get_revision(rev) ⇒ Object
Return a revision.
-
#last_revision ⇒ Object
Return the last revision.
-
#revise(options = {}) {|_self| ... } ⇒ Object
(also: #revise!)
Can accept options like owner or a comment.
-
#revision_count ⇒ Object
(also: #revisions_count)
The number of revisions.
-
#rollback(rev, options = {}) ⇒ Object
Rollback to an older revision.
Class Method Details
.included(base) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/glue/revisable.rb', line 63 def self.included base super base.module_eval %{ class Revision < #{base} include Revisable::Mixin refers_to #{base} end } base.has_many :revisions, base::Revision end |
Instance Method Details
#get_revision(rev) ⇒ Object
Return a revision.
99 100 101 102 |
# File 'lib/glue/revisable.rb', line 99 def get_revision rev return self if rev.to_i == self.revision self.revisions.find_one(:condition => "revision=#{rev}") end |
#last_revision ⇒ Object
Return the last revision.
106 107 108 |
# File 'lib/glue/revisable.rb', line 106 def last_revision self.revisions(:order => 'revision DESC', :limit => 1).first end |
#revise(options = {}) {|_self| ... } ⇒ Object Also known as: revise!
Can accept options like owner or a comment. You can specialize this in your app.
79 80 81 82 83 84 85 86 87 88 |
# File 'lib/glue/revisable.rb', line 79 def revise = {} if self.revision.nil? self.revision = 1 else self.revision += 1 end self.revisions << self.class::Revision.new(self, ) yield(self) if block_given? self.save end |
#revision_count ⇒ Object Also known as: revisions_count
The number of revisions.
112 113 114 |
# File 'lib/glue/revisable.rb', line 112 def revision_count self.revisions.count end |
#rollback(rev, options = {}) ⇒ Object
Rollback to an older revision.
93 94 95 |
# File 'lib/glue/revisable.rb', line 93 def rollback rev, = {} self.revise() { |obj| get_revision(rev).apply_to(obj) } end |