Module: Taggable::InstanceMethods

Defined in:
app/models/base_new.rb

Instance Method Summary collapse

Instance Method Details

#after_initializeObject



58
59
60
61
62
# File 'app/models/base_new.rb', line 58

def after_initialize
  super
  # set random generated uuid value
  self[:uuid] ||= Array.new(8) do UUID_TABLE[rand(UUID_TABLE.size)]; end.join
end

#canonical_uuidObject Also known as: cuuid

Returns canonicalized uuid which has the form of “#uuid_prefix-uuid”.



66
67
68
# File 'app/models/base_new.rb', line 66

def canonical_uuid
  "#{self.uuid_prefix}-#{self[:uuid]}"
end

#label_tag(tag_or_tag_uuid) ⇒ Object

Put the tag on the object.

This method just delegates the method call of Tag#label().



75
76
77
78
79
80
81
82
83
84
85
86
# File 'app/models/base_new.rb', line 75

def label_tag(tag_or_tag_uuid)
  tag = case tag_or_tag_uuid
        when String
          Tag[tag_or_tag_uuid]
        when Tag
          tag_or_tag_uuid
        else
          raise ArgumentError, "Invalid type: #{tag_or_tag_uuid.class}"
        end

  tag.label(self.uuid)
end

#unlabel_tag(tag_or_tag_uuid) ⇒ Object

Remove the labeled tag from the object

This method just delegates the method call of Tag#unlabel().



92
93
94
95
96
97
98
99
100
101
102
103
# File 'app/models/base_new.rb', line 92

def unlabel_tag(tag_or_tag_uuid)
  tag = case tag_or_tag_uuid
        when String
          Tag[tag_or_tag_uuid]
        when Tag
          tag_or_tag_uuid
        else
          raise ArgumentError, "Invalid type: #{tag_or_tag_uuid.class}"
        end

  tag.unlabel(self.uuid)
end

#uuid_prefixObject

read-only instance method to retrieve @uuid_prefix class variable.



54
55
56
# File 'app/models/base_new.rb', line 54

def uuid_prefix
  self.class.uuid_prefix
end