Module: Dcmgr::Models::Taggable::ClassMethods
- Defined in:
- lib/dcmgr/models/base_new.rb
Instance Method Summary collapse
-
#[](*args) ⇒ Object
Override Model.[] to add lookup by uuid.
-
#check_uuid_format(uuid) ⇒ Object
Checks the uuid syntax if it is for the Taggable class.
-
#trim_uuid(p_uuid) ⇒ Object
Returns the uuid string which is removed prefix part: /^(:?w+)-/.
-
#uuid_prefix(prefix = nil) ⇒ Object
Getter and setter for uuid_prefix of the class.
Instance Method Details
#[](*args) ⇒ Object
Override Model.[] to add lookup by uuid.
168 169 170 171 172 173 174 |
# File 'lib/dcmgr/models/base_new.rb', line 168 def [](*args) if args.size == 1 and args[0].is_a? String super(:uuid=>trim_uuid(args[0])) else super(*args) end end |
#check_uuid_format(uuid) ⇒ Object
Checks the uuid syntax if it is for the Taggable class.
191 192 193 |
# File 'lib/dcmgr/models/base_new.rb', line 191 def check_uuid_format(uuid) uuid =~ /^#{self.uuid_prefix}-/ end |
#trim_uuid(p_uuid) ⇒ Object
Returns the uuid string which is removed prefix part: /^(:?w+)-/.
182 183 184 185 186 187 188 |
# File 'lib/dcmgr/models/base_new.rb', line 182 def trim_uuid(p_uuid) regex = %r/^#{self.uuid_prefix}-/ if p_uuid and p_uuid =~ regex return p_uuid.sub(regex, '') end raise InvalidUUIDError, "Invalid uuid or unsupported uuid: #{p_uuid} in #{self}" end |
#uuid_prefix(prefix = nil) ⇒ Object
Getter and setter for uuid_prefix of the class.
152 153 154 155 156 157 158 159 160 161 |
# File 'lib/dcmgr/models/base_new.rb', line 152 def uuid_prefix(prefix=nil) if prefix raise UUIDPrefixDuplication, "Found collision for uuid_prefix key: #{prefix}" if Taggable.uuid_prefix_collection.has_key?(prefix) Taggable.uuid_prefix_collection[prefix]={:class=>self} @uuid_prefix = prefix end @uuid_prefix || (superclass.uuid_prefix if superclass.respond_to?(:uuid_prefix)) || raise("uuid prefix is unset for:#{self}") end |