Module: VestalVersions::VersionMethods
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/vestal_versions/users.rb,
lib/vestal_versions/version_tagging.rb
Overview
Instance methods included into VestalVersions::Version to enable version tagging.
Instance Method Summary collapse
-
#tag!(tag) ⇒ Object
Attaches the given string to the version tag column.
-
#tagged? ⇒ Boolean
Simply returns a boolean signifying whether the version instance has a tag value attached.
-
#user_with_name ⇒ Object
Overrides the
user
method created by the polymorphicbelongs_to
user association. -
#user_with_name=(value) ⇒ Object
Overrides the
user=
method created by the polymorphicbelongs_to
user association. - #validate_tags? ⇒ Boolean
Instance Method Details
#tag!(tag) ⇒ Object
Attaches the given string to the version tag column. If the uniqueness validation fails, nil is returned. Otherwise, the given string is returned.
35 36 37 38 |
# File 'lib/vestal_versions/version_tagging.rb', line 35 def tag!(tag) write_attribute(:tag, tag) save ? tag : nil end |
#tagged? ⇒ Boolean
Simply returns a boolean signifying whether the version instance has a tag value attached.
41 42 43 |
# File 'lib/vestal_versions/version_tagging.rb', line 41 def tagged? !tag.nil? end |
#user_with_name ⇒ Object
Overrides the user
method created by the polymorphic belongs_to
user association. If the association is absent, defaults to the user_name
string column. This allows VestalVersions::Version#user to either return an ActiveRecord::Base object or a string, depending on what is sent to the user_with_name=
method.
39 40 41 |
# File 'lib/vestal_versions/users.rb', line 39 def user_with_name user_without_name || user_name end |
#user_with_name=(value) ⇒ Object
Overrides the user=
method created by the polymorphic belongs_to
user association. Based on the class of the object given, either the user
association columns or the user_name
string column is populated.
46 47 48 49 50 51 |
# File 'lib/vestal_versions/users.rb', line 46 def user_with_name=(value) case value when ActiveRecord::Base then self.user_without_name = value else self.user_name = value end end |
#validate_tags? ⇒ Boolean
45 46 47 |
# File 'lib/vestal_versions/version_tagging.rb', line 45 def tagged? && tag != 'deleted' end |