Module: RSolr::Ext::Model

Defined in:
lib/rsolr-ext/model.rb

Overview

include this module into a plain ruby class: class Book

include RSolr::Ext::Model
connection = RSolr::Ext.connect
default_params = {:phrase_filters=>'type:book'}

end

Then: number_10 = Book.find_by_id(10)

Defined Under Namespace

Modules: Callbacks, Findable

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *args, &b) ⇒ Object

the wrapper method to the @_source object. If a method is missing, it gets sent to @_source with all of the original params and block



95
96
97
# File 'lib/rsolr-ext/model.rb', line 95

def method_missing(m, *args, &b)
  @_source.send(m, *args, &b)
end

Instance Attribute Details

#_sourceObject (readonly)

The original object passed in to the #new method



80
81
82
# File 'lib/rsolr-ext/model.rb', line 80

def _source
  @_source
end

Class Method Details

.included(base) ⇒ Object

Called by Ruby Module API extends this class object



73
74
75
76
77
# File 'lib/rsolr-ext/model.rb', line 73

def self.included(base)
  base.extend Callbacks
  base.extend Findable
  base.send :include, RSolr::Ext::Doc
end

Instance Method Details

#initialize(source_doc = {}) ⇒ Object

Constructor **for the class that is getting this module included** source_doc should be a hash or something similar calls each of after_initialize blocks



85
86
87
88
89
90
# File 'lib/rsolr-ext/model.rb', line 85

def initialize(source_doc={})
  @_source = source_doc.to_mash
  self.class.hooks.each do |h|
    instance_eval &h
  end
end