Module: AssayDepot::SearchModel

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

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

#facetsObject



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(options={})
  @internal_options = options[:search_options] || { }
  @search_query = options[:search_query] || ""
  @search_facets = options[:search_facets] || { }
end

#internal_resultsObject

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_options)
    @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