Module: Runes::Orm::ActiveRecord

Defined in:
lib/runes/orm/active_record.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#index_nameObject

Returns the value of attribute index_name.



4
5
6
# File 'lib/runes/orm/active_record.rb', line 4

def index_name
  @index_name
end

#type_nameObject

Returns the value of attribute type_name.



5
6
7
# File 'lib/runes/orm/active_record.rb', line 5

def type_name
  @type_name
end

Instance Method Details

#acts_as_indexable(options = {}) ⇒ Object



7
8
9
10
11
12
13
14
# File 'lib/runes/orm/active_record.rb', line 7

def acts_as_indexable(options={})
  send :include, InstanceMethods
  @index_name = self.name.underscore.gsub(/\//, '-').pluralize
  @type_name = self.name.underscore.gsub(/\//, '-').singularize
  Runes::Base.set_actor(@index_name)
  after_destroy :destroy_object_from_index
  after_save :add_object_to_index
end

#search(query) ⇒ Object



16
17
18
19
20
# File 'lib/runes/orm/active_record.rb', line 16

def search(query)
  search = Runes::Base.search(query, @index_name)
  results = search.map{|result| result.ar_equivalence}
  return results.sort_by(&:created_at)
end