Class: ROM::Cassandra::Gateway

Inherits:
Gateway
  • Object
show all
Defined in:
lib/rom/cassandra/gateway.rb

Overview

The gateway to the keyspace of the Cassandra cluster

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*options) ⇒ Gateway

Initializes the ROM gateway to the Cassandra cluster

Examples:

ROM::Cassandra::Gateway.new(
  hosts:    ["10.0.1.1", "10.0.1.2"],
  port:     9042,
  username: "admin",
  password: "foo"
)
ROM::Cassandra::Gateway.new(
  "http://10.0.1.1:9042",
  username: "admin",
  password: "foo"
)

Parameters:

  • options (Hash)


44
45
46
47
# File 'lib/rom/cassandra/gateway.rb', line 44

def initialize(*options)
  @session  = Session.new(*options)
  @datasets = {}
end

Instance Attribute Details

#datasetsHash (readonly)

Returns The list of registered datasets.

Returns:

  • (Hash)

    The list of registered datasets



23
24
25
# File 'lib/rom/cassandra/gateway.rb', line 23

def datasets
  @datasets
end

#sessionROM::Cassandra::Session (readonly)

Returns The current session.

Returns:



17
18
19
# File 'lib/rom/cassandra/gateway.rb', line 17

def session
  @session
end

Instance Method Details

#[](name) ⇒ ROM::Cassandra::Dataset

Returns the registered dataset

Parameters:

  • name (#to_sym)

    The full name of the table

Returns:



76
77
78
# File 'lib/rom/cassandra/gateway.rb', line 76

def [](name)
  datasets[name.to_sym]
end

#dataset(name) ⇒ ROM::Cassandra::Dataset

Registers a new dataset

Examples:

dataset "foo.bar"

Parameters:

  • name (#to_sym)

    The full name of the table

Returns:



66
67
68
# File 'lib/rom/cassandra/gateway.rb', line 66

def dataset(name)
  @datasets[name.to_sym] = Dataset.new(session, *split(name))
end

#dataset?(name) ⇒ Boolean

Checks whether the dataset is registered

Parameters:

  • name (#to_sym)

    The full name of the table

Returns:

  • (Boolean)


86
87
88
# File 'lib/rom/cassandra/gateway.rb', line 86

def dataset?(name)
  self[name] ? true : false
end

#migrate(options = {}) ⇒ undefined

Migrates the Cassandra cluster to given version

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :version (Integer, nil)

Returns:

  • (undefined)


97
98
99
100
101
102
# File 'lib/rom/cassandra/gateway.rb', line 97

def migrate(options = {})
  settings = options.select { |key| [:path, :logger].include? key }
  target   = options.select { |key| key.equal? :version }

  Migrations::Migrator.new(session, settings).apply(target)
end

#optionsHash

The options of the initialized session

Returns:

  • (Hash)


53
54
55
# File 'lib/rom/cassandra/gateway.rb', line 53

def options
  session.uri
end