Module: MetaSearch::Searches::ActiveRecord::ClassMethods

Defined in:
lib/meta_search/searches/active_record.rb

Instance Method Summary (collapse)

Instance Method Details

- (Boolean) _metasearch_association_authorized?(name, metasearch_object)



63
64
65
66
67
68
69
70
# File 'lib/meta_search/searches/active_record.rb', line 63

def _metasearch_association_authorized?(name, metasearch_object)
  name = name.to_s
  if self._metasearch_include_associations.empty?
    !_metasearch_excludes_association?(name, metasearch_object)
  else
    _metasearch_includes_association?(name, metasearch_object)
  end
end

- (Boolean) _metasearch_attribute_authorized?(name, metasearch_object)



54
55
56
57
58
59
60
61
# File 'lib/meta_search/searches/active_record.rb', line 54

def _metasearch_attribute_authorized?(name, metasearch_object)
  name = name.to_s
  if self._metasearch_include_attributes.empty?
    !_metasearch_excludes_attribute?(name, metasearch_object)
  else
    _metasearch_includes_attribute?(name, metasearch_object)
  end
end

- (Boolean) _metasearch_method_authorized?(name, metasearch_object)



48
49
50
51
52
# File 'lib/meta_search/searches/active_record.rb', line 48

def _metasearch_method_authorized?(name, metasearch_object)
  name = name.to_s
  meth = self._metasearch_methods[name]
  meth && (meth[:if] ? meth[:if].call(metasearch_object) : true)
end

- (Object) metasearch(params = nil, opts = nil) Also known as: search

Prepares the search to run against your model. Returns an instance of MetaSearch::Builder, which behaves pretty much like an ActiveRecord::Relation, in that it doesn't actually query the database until you do something that requires it to do so.

Options:

  • params - a hash of valid searches with keys that are valid according to the docs in MetaSearch::Where.

  • opts - A hash of additional information that will be passed through to the search's Builder object. search_key, if present, will override the default param name, 'search', in any sort_links generated by this Builder. All other keys are passed untouched to the builder, and available from the Builder's options reader for use in :if blocks supplied to attr_searchable and friends.



41
42
43
44
# File 'lib/meta_search/searches/active_record.rb', line 41

def metasearch(params = nil, opts = nil)
  builder = Searches.for(self).new(self, opts || {})
  builder.build(params || {})
end