Module: MarkMapper::Plugins::Persistence::ClassMethods

Defined in:
lib/mark_mapper/plugins/persistence.rb

Instance Method Summary collapse

Instance Method Details

#collectionObject


56
57
58
59
# File 'lib/mark_mapper/plugins/persistence.rb', line 56

def collection
  assert_supported
  database.collection(collection_name)
end

#collection_nameObject


47
48
49
50
51
52
53
54
# File 'lib/mark_mapper/plugins/persistence.rb', line 47

def collection_name
  assert_supported
  @collection_name ||= begin
    name = self.to_s.tableize.gsub(/\//, '.')
    name = self.class.to_s.downcase if name[0] == '#'
    name
  end
end

#connection(marklogic_connection = nil) ⇒ Object


17
18
19
20
21
22
23
24
25
# File 'lib/mark_mapper/plugins/persistence.rb', line 17

def connection(marklogic_connection=nil)
  assert_supported
  if marklogic_connection.nil? && MarkMapper.connection?
    @connection ||= MarkMapper.connection
  else
    @connection = marklogic_connection
  end
  @connection
end

#databaseObject


37
38
39
40
# File 'lib/mark_mapper/plugins/persistence.rb', line 37

def database
  assert_supported
  @database ||= MarkMapper.application.content_databases[0]
end

#database=(database) ⇒ Object


32
33
34
35
# File 'lib/mark_mapper/plugins/persistence.rb', line 32

def database=(database)
  assert_supported
  @database = database
end

#database_nameObject


27
28
29
30
# File 'lib/mark_mapper/plugins/persistence.rb', line 27

def database_name
  assert_supported
  @database.database_name
end

#inherited(subclass) ⇒ Object


8
9
10
11
12
13
14
15
# File 'lib/mark_mapper/plugins/persistence.rb', line 8

def inherited(subclass)
  unless subclass.embeddable?
    subclass.connection(connection)
    subclass.database = database
    subclass.set_collection_name(collection_name) unless subclass.explicit_collection_defined?
  end
  super
end

#set_collection_name(name) ⇒ Object


42
43
44
45
# File 'lib/mark_mapper/plugins/persistence.rb', line 42

def set_collection_name(name)
  assert_supported
  @collection_name = name
end