Class: SimpleMetrics::DashboardRepository
- Inherits:
-
Object
- Object
- SimpleMetrics::DashboardRepository
- Defined in:
- lib/simple_metrics/dashboard_repository.rb
Class Method Summary collapse
- .ensure_index ⇒ Object
- .find_all ⇒ Object
- .find_one(id) ⇒ Object
- .find_one_by_name(name) ⇒ Object
- .remove(id) ⇒ Object
- .save(dashboard) ⇒ Object
- .truncate_collections ⇒ Object
- .update(dashboard) ⇒ Object
Class Method Details
.ensure_index ⇒ Object
36 37 38 39 40 |
# File 'lib/simple_metrics/dashboard_repository.rb', line 36 def ensure_index collection.ensure_index([['created_at', ::Mongo::ASCENDING]]) collection.ensure_index([['updated_at', ::Mongo::ASCENDING]]) collection.ensure_index([['name', ::Mongo::ASCENDING]]) end |
.find_all ⇒ Object
15 16 17 18 |
# File 'lib/simple_metrics/dashboard_repository.rb', line 15 def find_all results = collection.find.sort([['name', ::Mongo::ASCENDING]]).to_a dashboards(results) if results end |
.find_one(id) ⇒ Object
6 7 8 |
# File 'lib/simple_metrics/dashboard_repository.rb', line 6 def find_one(id) dashboard(collection.find_one(BSON::ObjectId.from_string(id))) end |
.find_one_by_name(name) ⇒ Object
10 11 12 13 |
# File 'lib/simple_metrics/dashboard_repository.rb', line 10 def find_one_by_name(name) result = collection.find({ :name => name }).to_a.first dashboard(result) if result end |
.remove(id) ⇒ Object
28 29 30 |
# File 'lib/simple_metrics/dashboard_repository.rb', line 28 def remove(id) collection.remove("_id" => BSON::ObjectId.from_string(id)) end |
.save(dashboard) ⇒ Object
20 21 22 |
# File 'lib/simple_metrics/dashboard_repository.rb', line 20 def save(dashboard) collection.insert(dashboard.attributes.merge(:created_at => Time.now.utc, :updated_at => Time.now.utc)) end |
.truncate_collections ⇒ Object
32 33 34 |
# File 'lib/simple_metrics/dashboard_repository.rb', line 32 def truncate_collections collection.remove end |
.update(dashboard) ⇒ Object
24 25 26 |
# File 'lib/simple_metrics/dashboard_repository.rb', line 24 def update(dashboard) collection.update({ "_id" => dashboard.id }, { "$set" => dashboard.attributes.merge(:updated_at => Time.now.utc).reject { |k, v| k == 'id' } }) end |