Module: Dcmgr::Models::Taggable::InstanceMethods

Defined in:
lib/dcmgr/models/base_new.rb

Instance Method Summary collapse

Instance Method Details

#after_initializeObject



62
63
64
65
66
# File 'lib/dcmgr/models/base_new.rb', line 62

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”.



70
71
72
# File 'lib/dcmgr/models/base_new.rb', line 70

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().



79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/dcmgr/models/base_new.rb', line 79

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

#to_hashObject



109
110
111
# File 'lib/dcmgr/models/base_new.rb', line 109

def to_hash()
  self.values.dup.merge({:id=>canonical_uuid, :uuid=>canonical_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().



96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/dcmgr/models/base_new.rb', line 96

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.



58
59
60
# File 'lib/dcmgr/models/base_new.rb', line 58

def uuid_prefix
  self.class.uuid_prefix
end