Module: Couchbase::Model::IdPrefix::ClassMethods

Defined in:
lib/couchbase/model/id_prefix.rb

Instance Method Summary collapse

Instance Method Details

#class_from_id(id) ⇒ Object



55
56
57
# File 'lib/couchbase/model/id_prefix.rb', line 55

def class_from_id(id)
  prefix_from_id(id).classify.constantize
end

#id_parts(id) ⇒ Object



59
60
61
# File 'lib/couchbase/model/id_prefix.rb', line 59

def id_parts(id)
  id.to_s.split(':')
end

#id_prefixObject

FIXME Need to handle cases where there’s no id, or we fail or w/e



31
32
33
# File 'lib/couchbase/model/id_prefix.rb', line 31

def id_prefix
  @_id_prefix ||= name.underscore
end

#next_prefixed_idObject



35
36
37
# File 'lib/couchbase/model/id_prefix.rb', line 35

def next_prefixed_id
  prefixed_id(next_unprefixed_id)
end

#next_unprefixed_idObject



39
40
41
# File 'lib/couchbase/model/id_prefix.rb', line 39

def next_unprefixed_id
  Couchbase::Model::UUID.generator.next(1, thread_storage[:uuid_algorithm])
end

#prefix_from_id(id) ⇒ Object



51
52
53
# File 'lib/couchbase/model/id_prefix.rb', line 51

def prefix_from_id(id)
  id_parts(id).first
end

#prefixed_id(id) ⇒ Object



43
44
45
# File 'lib/couchbase/model/id_prefix.rb', line 43

def prefixed_id(id)
  "#{id_prefix}:#{unprefixed_id(id)}"
end

#unprefixed_id(id) ⇒ Object



47
48
49
# File 'lib/couchbase/model/id_prefix.rb', line 47

def unprefixed_id(id)
  id_parts(id).last
end