Class: MongoImport::Snapshot
- Inherits:
-
Object
- Object
- MongoImport::Snapshot
- Defined in:
- lib/mongo-import/snapshot.rb
Instance Attribute Summary collapse
-
#collection ⇒ Object
readonly
Returns the value of attribute collection.
-
#db ⇒ Object
readonly
Returns the value of attribute db.
-
#opts ⇒ Object
readonly
Returns the value of attribute opts.
Instance Method Summary collapse
-
#import ⇒ Object
returns true if the import succeeded.
-
#initialize(name, opts = {}) ⇒ Snapshot
constructor
A new instance of Snapshot.
Constructor Details
#initialize(name, opts = {}) ⇒ Snapshot
Returns a new instance of Snapshot.
11 12 13 14 15 16 17 18 |
# File 'lib/mongo-import/snapshot.rb', line 11 def initialize(name, opts={}) raise ArgumentError, ':db is missing' unless opts[:db] raise ArgumentError, ':collection is missing' unless opts[:collection] defaults = {host: 'localhost', port: 27017, exec: 'mongoimport', path: 'spec/snapshots'} @opts = OpenStruct.new(defaults.merge(opts)) @path = @opts.path @name = name end |
Instance Attribute Details
#collection ⇒ Object (readonly)
Returns the value of attribute collection.
9 10 11 |
# File 'lib/mongo-import/snapshot.rb', line 9 def collection @collection end |
#db ⇒ Object (readonly)
Returns the value of attribute db.
9 10 11 |
# File 'lib/mongo-import/snapshot.rb', line 9 def db @db end |
#opts ⇒ Object (readonly)
Returns the value of attribute opts.
9 10 11 |
# File 'lib/mongo-import/snapshot.rb', line 9 def opts @opts end |
Instance Method Details
#import ⇒ Object
returns true if the import succeeded
21 22 23 24 25 26 27 |
# File 'lib/mongo-import/snapshot.rb', line 21 def import raise "Could not find #{@opts.exec} in your PATH" unless system("which #{opts.exec} > /dev/null") file = File.join(@path, "#{@name}.json") cmd = "#{opts.exec} --host #{opts.host} --port #{opts.port} --drop --db #{opts.db} --collection #{opts.collection} #{file}" `#{cmd}` end |