Module: Rethinker::Document::Core::ClassMethods

Defined in:
lib/rethinker/document/core.rb

Instance Method Summary collapse

Instance Method Details

#ensure_table!Object

Thread safe because the operation is idempotent (no error if we try to create the table twice)



31
32
33
34
35
# File 'lib/rethinker/document/core.rb', line 31

def ensure_table!
  root_class.class_eval do
    @table_created ||= !!self.count
  end
end

#tableObject

Even though we are using class variables, it’s threads-safe. It’s still racy, but the race is harmless.



23
24
25
26
27
# File 'lib/rethinker/document/core.rb', line 23

def table
  root_class.class_eval do
    @table ||= RethinkDB::RQL.new.table(table_name).freeze
  end
end

#table_nameObject



17
18
19
# File 'lib/rethinker/document/core.rb', line 17

def table_name
  root_class.name.underscore.gsub('/', '__').pluralize
end