Module: Memories::ClassMethods
- Defined in:
- lib/memories/base.rb
Overview
:nodoc: all
Instance Method Summary collapse
-
#forget(*props) ⇒ Object
If you’d like to exclude certain properties from versioning, simply pass those properties to this method: class MyDocument < CouchRest::Model::Base use_database MY_DATABASE include Memories.
- #forget_properties ⇒ Object
- #forget_properties=(props) ⇒ Object
-
#remember(*props) ⇒ Object
If you’d like to explicitly define which properties you want versioned simply pass those properties to this method: class MyDocument < CouchRest::Model::Base use_database MY_DATABASE include Memories.
-
#remember_attachments ⇒ Object
Returns a list of attachment patterns for versioning.
-
#remember_attachments!(*attachment_names) ⇒ Object
If you’d like to version attachments, simply call this macro in your class definition: .
-
#remember_attachments? ⇒ Boolean
Returns true if self is set up to remember attachments.
- #remember_properties ⇒ Object
- #remember_properties=(props) ⇒ Object
Instance Method Details
#forget(*props) ⇒ Object
If you’d like to exclude certain properties from versioning, simply pass those properties to this method:
class MyDocument < CouchRest::Model::Base
use_database MY_DATABASE
include Memories
forget :prop1, :prop2
property :prop1 #not versioned
property :prop2 #not versioned
property :prop3 #versioned
end
38 39 40 41 42 |
# File 'lib/memories/base.rb', line 38 def forget(*props) #:doc: raise StandardError, "Ambiguous use of both #remember and #forget." if @remember_called @forget_called = true self.forget_properties += props.map {|p| p.to_s} end |
#forget_properties ⇒ Object
117 118 119 |
# File 'lib/memories/base.rb', line 117 def forget_properties @forget_properties ||= ["couchrest-type", "_id", "_rev", "_attachments", "milestone_memories"] end |
#forget_properties=(props) ⇒ Object
121 122 123 |
# File 'lib/memories/base.rb', line 121 def forget_properties=(props) @forget_properties = props end |
#remember(*props) ⇒ Object
If you’d like to explicitly define which properties you want versioned simply pass those properties to this method:
class MyDocument < CouchRest::Model::Base
use_database MY_DATABASE
include Memories
remember :prop1, :prop2
property :prop1 #versioned
property :prop2 #versioned
property :prop3 # not versioned
end
58 59 60 61 62 63 64 65 66 67 |
# File 'lib/memories/base.rb', line 58 def remember(*props) #:doc: raise StandardError, "Ambiguous use of both #remember and #forget." if @forget_called @remember_called = true props = props.map {|p| p.to_s} if self.remember_properties.nil? self.remember_properties = props else self.remember_properties += props end end |
#remember_attachments ⇒ Object
Returns a list of attachment patterns for versioning. The list may contain strings, denoting the names of attachments to version, but it may also contain regular expressions, indicating that attachments with matching names should be versioned.
78 |
# File 'lib/memories/base.rb', line 78 def ; @remember_attachments || []; end |
#remember_attachments!(*attachment_names) ⇒ Object
If you’d like to version attachments, simply call this macro in your class definition:
class MyDoc < CouchRest::Model::Base
use_database MY_DB
include Memories
end
If you only want specific attachments versioned, pass strings and/or regular expressions to this macro. Any attachments with matching names will be versioned.
class HtmlPage < CouchRest::Model::Base
use_database MY_DB
include Memories
"image.png", %r{stylesheets/.*}
end
101 102 103 104 105 106 107 |
# File 'lib/memories/base.rb', line 101 def (*) #:doc: if .empty? @remember_attachments = [/.*/] else @remember_attachments = end end |
#remember_attachments? ⇒ Boolean
Returns true if self is set up to remember attachments. False otherwise.
70 71 72 |
# File 'lib/memories/base.rb', line 70 def #:doc: @remember_attachments ? true : false end |
#remember_properties ⇒ Object
109 110 111 |
# File 'lib/memories/base.rb', line 109 def remember_properties @remember_properties ||= nil end |
#remember_properties=(props) ⇒ Object
113 114 115 |
# File 'lib/memories/base.rb', line 113 def remember_properties=(props) @remember_properties = props end |