Class: ROM::Mongo::Adapter

Inherits:
Adapter
  • Object
show all
Defined in:
lib/rom/mongo/adapter.rb

Defined Under Namespace

Modules: RelationInclusion Classes: Dataset

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Adapter

Returns a new instance of Adapter.



40
41
42
43
44
45
# File 'lib/rom/mongo/adapter.rb', line 40

def initialize(*args)
  super
  @connection = Moped::Session.new(["#{uri.host}:#{uri.port}"])
  @connection.use uri.path.gsub('/', '')
  @collections = {}
end

Instance Attribute Details

#collectionsObject (readonly)

Returns the value of attribute collections.



38
39
40
# File 'lib/rom/mongo/adapter.rb', line 38

def collections
  @collections
end

Class Method Details

.schemesObject



4
5
6
# File 'lib/rom/mongo/adapter.rb', line 4

def self.schemes
  [:mongo]
end

Instance Method Details

#[](name) ⇒ Object



47
48
49
# File 'lib/rom/mongo/adapter.rb', line 47

def [](name)
  collections.fetch(name)
end

#command_namespaceObject



59
60
61
# File 'lib/rom/mongo/adapter.rb', line 59

def command_namespace
  Mongo::Commands
end

#dataset(name, header) ⇒ Object



51
52
53
# File 'lib/rom/mongo/adapter.rb', line 51

def dataset(name, header)
  collections[name] = Dataset.new(connection[name], header)
end

#dataset?(name) ⇒ Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/rom/mongo/adapter.rb', line 55

def dataset?(name)
  connection.collection_names.include?(name.to_s)
end

#extend_relation_class(klass) ⇒ Object



63
64
65
# File 'lib/rom/mongo/adapter.rb', line 63

def extend_relation_class(klass)
  klass.send(:include, RelationInclusion)
end