Module: VestalVersions::Tagging::VersionMethods

Defined in:
lib/vestal_versions/tagging.rb

Overview

Instance methods included into VestalVersions::Version to enable version tagging.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object

:nodoc:



31
32
33
34
35
# File 'lib/vestal_versions/tagging.rb', line 31

def self.included(base) # :nodoc:
  base.class_eval do
    validates_uniqueness_of :tag, :scope => [:versioned_id, :versioned_type], :if => :validate_tags?
  end
end

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.



39
40
41
42
# File 'lib/vestal_versions/tagging.rb', line 39

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.

Returns:

  • (Boolean)


45
46
47
# File 'lib/vestal_versions/tagging.rb', line 45

def tagged?
  !tag.nil?
end

#validate_tags?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/vestal_versions/tagging.rb', line 49

def validate_tags?
  tagged? && tag != 'deleted'
end