Module: AssayDepot::SearchModel
- Included in:
- AddNote, Category, DynamicForm, Info, ListItem, Organization, Provider, ProviderWare, QuoteGroup, QuotedWare, TokenAuth, User, Ware, WareProvider, Webhook
- Defined in:
- lib/assaydepot/model.rb
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
- #facets ⇒ Object
- #find(query) ⇒ Object
- #initialize(options = {}) ⇒ Object
-
#internal_results ⇒ Object
Overridden from Model.
- #where(conditions = {}) ⇒ Object
Class Method Details
.included(base) ⇒ Object
43 44 45 46 47 48 49 50 51 |
# File 'lib/assaydepot/model.rb', line 43 def self.included(base) base.extend AssayDepot::Model::ClassMethods base.extend ClassMethods base.include AssayDepot::Model base.include AssayDepot::Pageable attr_accessor :search_query attr_accessor :search_facets end |
Instance Method Details
#facets ⇒ Object
59 60 61 |
# File 'lib/assaydepot/model.rb', line 59 def facets internal_results["facets"] end |
#find(query) ⇒ Object
63 64 65 66 67 |
# File 'lib/assaydepot/model.rb', line 63 def find(query) result = self.clone result.search_query = query result end |
#initialize(options = {}) ⇒ Object
53 54 55 56 57 |
# File 'lib/assaydepot/model.rb', line 53 def initialize(={}) @internal_options = [:search_options] || { } @search_query = [:search_query] || "" @search_facets = [:search_facets] || { } end |
#internal_results ⇒ Object
Overridden from Model
76 77 78 79 80 81 82 |
# File 'lib/assaydepot/model.rb', line 76 def internal_results unless @internal_results results = Client.new(endpoint: self.class.endpoint(nil)).search(query: search_query, facets: search_facets, params: ) @internal_results = JSON.parse(results) end @internal_results end |
#where(conditions = {}) ⇒ Object
69 70 71 72 73 |
# File 'lib/assaydepot/model.rb', line 69 def where(conditions={}) result = self.clone result.search_facets = self.search_facets ? self.search_facets.merge(conditions) : conditions result end |