Class: Obtenir::Database
- Inherits:
-
Object
- Object
- Obtenir::Database
- Defined in:
- lib/obtenir/database.rb
Instance Method Summary collapse
-
#initialize(database, data) ⇒ Database
constructor
A new instance of Database.
- #save? ⇒ Boolean
Constructor Details
#initialize(database, data) ⇒ Database
6 7 8 9 |
# File 'lib/obtenir/database.rb', line 6 def initialize(database, data) @database = database @data = data end |
Instance Method Details
#save? ⇒ Boolean
11 12 13 14 15 16 17 18 |
# File 'lib/obtenir/database.rb', line 11 def save? client = Mongo::Client.new([ '127.0.0.1:27017' ], :database => @database) collection = client[:people] result = collection.insert_one(@data) true rescue StandardError => error puts "Error: #{error.} occurred when saving data".colorize(:red) end |