Class: Dolly::MangoIndex
- Inherits:
-
Object
- Object
- Dolly::MangoIndex
- Extended by:
- Forwardable
- Defined in:
- lib/dolly/mango_index.rb
Constant Summary collapse
- ALL_DOCS =
'_all_docs'
- DESIGN =
'_index'
- ROWS_KEY =
:rows
- DESIGN_PREFIX =
'_design/'
Class Method Summary collapse
- .all ⇒ Object
- .create(name, fields, type = 'json') ⇒ Object
- .create_in_database(database, name, fields, type = 'json') ⇒ Object
- .delete(index_doc) ⇒ Object
- .delete_all ⇒ Object
- .find_by_fields(fields) ⇒ Object
Class Method Details
.all ⇒ Object
17 18 19 |
# File 'lib/dolly/mango_index.rb', line 17 def all get(DESIGN)[:indexes] end |
.create(name, fields, type = 'json') ⇒ Object
21 22 23 |
# File 'lib/dolly/mango_index.rb', line 21 def create(name, fields, type = 'json') post(DESIGN, build_index_structure(name, fields, type)) end |
.create_in_database(database, name, fields, type = 'json') ⇒ Object
25 26 27 28 29 30 |
# File 'lib/dolly/mango_index.rb', line 25 def create_in_database(database, name, fields, type = 'json') db_conn = connection_for_database(database) return "Migrations for #{database} skiped." if db_conn.skip_migrations? db_conn.post(DESIGN, build_index_structure(name, fields, type)) end |
.delete(index_doc) ⇒ Object
44 45 46 47 |
# File 'lib/dolly/mango_index.rb', line 44 def delete(index_doc) resource = "#{DESIGN}/#{index_doc[:ddoc]}/json/#{index_doc[:name]}" connection.delete(resource, escape: false) end |
.delete_all ⇒ Object
37 38 39 40 41 42 |
# File 'lib/dolly/mango_index.rb', line 37 def delete_all all.each do |index_doc| next if index_doc[:ddoc].nil? delete(index_doc) end end |
.find_by_fields(fields) ⇒ Object
32 33 34 35 |
# File 'lib/dolly/mango_index.rb', line 32 def find_by_fields(fields) rows = get(ALL_DOCS, key: key_from_fields(fields))[ROWS_KEY] (rows && rows.any?) end |