Class: MongoDbUtils::Model::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/mongo-db-utils/models/config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



10
11
12
13
# File 'lib/mongo-db-utils/models/config.rb', line 10

def initialize
  @dbs = []
  @buckets = []
end

Instance Attribute Details

#backup_folderObject

Returns the value of attribute backup_folder.



8
9
10
# File 'lib/mongo-db-utils/models/config.rb', line 8

def backup_folder
  @backup_folder
end

#bucketsObject (readonly)

Returns the value of attribute buckets.



6
7
8
# File 'lib/mongo-db-utils/models/config.rb', line 6

def buckets
  @buckets
end

#dbsObject (readonly)

Returns the value of attribute dbs.



6
7
8
# File 'lib/mongo-db-utils/models/config.rb', line 6

def dbs
  @dbs
end

#writer=(value) ⇒ Object (writeonly)

Sets the attribute writer

Parameters:

  • value

    the value to set the attribute writer to.



7
8
9
# File 'lib/mongo-db-utils/models/config.rb', line 7

def writer=(value)
  @writer = value
end

Instance Method Details

#add_bucket(bucket) ⇒ Object

because we are serializing the config - the bucket may be nil at this point



48
49
50
51
52
53
54
# File 'lib/mongo-db-utils/models/config.rb', line 48

def add_bucket(bucket)
  @buckets = [] if @buckets.nil?
  unless already_contains_bucket?(bucket)
    @buckets << bucket
    save
  end
end

#add_replica_set(uri, name) ⇒ Object



33
34
35
# File 'lib/mongo-db-utils/models/config.rb', line 33

def add_replica_set(uri, name)
  add_db ReplicaSetDb.new(uri,name)
end

#add_single_db(uri) ⇒ Object



38
39
40
# File 'lib/mongo-db-utils/models/config.rb', line 38

def add_single_db(uri)
  add_db Db.new(uri)
end

#already_contains(db) ⇒ Object



42
43
44
# File 'lib/mongo-db-utils/models/config.rb', line 42

def already_contains(db)
  !@dbs.find{|current| current.uri == db.uri }.nil?
end

#already_contains_bucket?(bucket) ⇒ Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/mongo-db-utils/models/config.rb', line 56

def already_contains_bucket?(bucket)
  !@buckets.find{ |b| b.to_s == bucket.to_s}.nil?
end

#empty?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/mongo-db-utils/models/config.rb', line 15

def empty?
  @dbs.nil? || @dbs.empty?
end

#flushObject



23
24
25
26
# File 'lib/mongo-db-utils/models/config.rb', line 23

def flush
  @dbs = []
  @writer.flush
end

#has_buckets?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/mongo-db-utils/models/config.rb', line 19

def has_buckets?
  !@buckets.nil? && !@buckets.empty?
end

#remove_db(db) ⇒ Object



28
29
30
31
# File 'lib/mongo-db-utils/models/config.rb', line 28

def remove_db(db)
  @dbs = @dbs - [db]
  save
end