Class: BuildBuddy::Recorder
- Inherits:
-
Object
- Object
- BuildBuddy::Recorder
- Includes:
- Celluloid, Celluloid::Internals::Logger
- Defined in:
- lib/build_buddy/recorder.rb
Instance Method Summary collapse
- #get_build_data(id) ⇒ Object
-
#initialize ⇒ Recorder
constructor
A new instance of Recorder.
- #record_build_data(build_data) ⇒ Object
- #update_build_data(build_data) ⇒ Object
Constructor Details
#initialize ⇒ Recorder
Returns a new instance of Recorder.
12 13 14 15 |
# File 'lib/build_buddy/recorder.rb', line 12 def initialize() @mongo ||= Mongo::Client.new([ '127.0.0.1:27017' ], :database => 'build-buddy') info "Connected to MongoDB" end |
Instance Method Details
#get_build_data(id) ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'lib/build_buddy/recorder.rb', line 30 def get_build_data(id) builds = @mongo[:builds] document = builds.find({ :_id => BSON::ObjectId.from_string(id) }, { :limit => 1 }).first if document.nil? return nil end BuildData.new(document) end |
#record_build_data(build_data) ⇒ Object
17 18 19 20 21 |
# File 'lib/build_buddy/recorder.rb', line 17 def record_build_data(build_data) builds = @mongo[:builds] result = builds.insert_one(build_data.to_h) build_data._id = result.inserted_id end |
#update_build_data(build_data) ⇒ Object
23 24 25 26 27 28 |
# File 'lib/build_buddy/recorder.rb', line 23 def update_build_data(build_data) unless build_data._id.nil? builds = @mongo[:builds] builds.replace_one({ :_id => build_data._id }, build_data.to_h) end end |