Module: Elasticord::Base::ClassMethods
- Included in:
- Elasticord::Base
- Defined in:
- lib/elasticord/base.rb
Instance Method Summary collapse
- #create(attributes = {}) ⇒ Object
- #delete_all ⇒ Object
- #delete_by_query(attributes = {}) ⇒ Object
- #get(id) ⇒ Object
- #index ⇒ Object
- #index=(new_index) ⇒ Object
- #refresh_index ⇒ Object
- #search(query = {}) ⇒ Object
- #type ⇒ Object
Instance Method Details
#create(attributes = {}) ⇒ Object
11 12 13 14 15 16 17 18 19 |
# File 'lib/elasticord/base.rb', line 11 def create(attributes = {}) result = ORM::Create.one(index, type, attributes) return false unless result attributes[:id] ||= result['_id'] self.new(attributes) end |
#delete_all ⇒ Object
43 44 45 |
# File 'lib/elasticord/base.rb', line 43 def delete_all ORM::Delete.all(index) end |
#delete_by_query(attributes = {}) ⇒ Object
39 40 41 |
# File 'lib/elasticord/base.rb', line 39 def delete_by_query(attributes = {}) ORM::Delete.by_query(index, type, attributes) end |
#get(id) ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/elasticord/base.rb', line 21 def get(id) result = ORM::Get.one(index, type, id) return false unless result self.new(result.merge({ 'id' => id })) end |
#index ⇒ Object
51 52 53 54 55 56 57 |
# File 'lib/elasticord/base.rb', line 51 def index return @index if defined?(@index) @index = (superclass.index || '').dup if superclass.respond_to? :index @index = @index.presence || Elasticord::Config.get(:index_namespace) end |
#index=(new_index) ⇒ Object
59 60 61 |
# File 'lib/elasticord/base.rb', line 59 def index=(new_index) @index = new_index end |
#refresh_index ⇒ Object
47 48 49 |
# File 'lib/elasticord/base.rb', line 47 def refresh_index ORM::Index.refresh(index) end |
#search(query = {}) ⇒ Object
29 30 31 32 33 34 35 36 37 |
# File 'lib/elasticord/base.rb', line 29 def search(query = {}) results = ORM::Get.by_query(index, type, query) results[:data] = results[:data].map do |attributes| self.new(attributes) end results end |
#type ⇒ Object
63 64 65 66 67 68 69 |
# File 'lib/elasticord/base.rb', line 63 def type return @type if defined?(@type) return (@type = '_all') if name.nil? || name == 'Elasticord::Base' @type = name.split('::').last.underscore end |