Module: Dolly::DocumentType

Included in:
Document, IdentityProperties, Query
Defined in:
lib/dolly/document_type.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



46
47
48
# File 'lib/dolly/document_type.rb', line 46

def self.included(base)
  base.extend(ClassMethods)
end

Instance Method Details

#base_idObject



16
17
18
# File 'lib/dolly/document_type.rb', line 16

def base_id
  self.id.sub(%r{^#{name_paramitized}#{type_sep}}, '')
end

#class_nameObject



24
25
26
# File 'lib/dolly/document_type.rb', line 24

def class_name
  is_a?(Class) ? name : self.class.name
end

#name_paramitizedObject



20
21
22
# File 'lib/dolly/document_type.rb', line 20

def name_paramitized
  class_name.split("::").last.underscore
end

#namespace_key(key) ⇒ Object



11
12
13
14
# File 'lib/dolly/document_type.rb', line 11

def namespace_key(key)
  return "#{key}" if "#{key}" =~ %r{^#{name_paramitized}#{type_sep}}
  "#{name_paramitized}#{type_sep}#{key}"
end

#namespace_keys(keys) ⇒ Object



7
8
9
# File 'lib/dolly/document_type.rb', line 7

def namespace_keys(keys)
  keys.map { |key| namespace_key key }
end

#partitioned?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/dolly/document_type.rb', line 42

def partitioned?
  false
end

#set_typeObject



32
33
34
35
# File 'lib/dolly/document_type.rb', line 32

def set_type
  return unless typed?
  write_attribute(:type, name_paramitized)
end

#type_sepObject



37
38
39
40
# File 'lib/dolly/document_type.rb', line 37

def type_sep
  return ':' if partitioned?
  '/'
end

#typed?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/dolly/document_type.rb', line 28

def typed?
  respond_to?(:type)
end