Module: MongoMapper::Mixins::Properties
- Defined in:
- lib/mixins/properties.rb
Overview
Patches to the CouchRest Properties module: Adds the “attributes” method plus some fulltext relevant stuff.
Samples:
data = SERVER.default_database.view('CouchSphinxIndex/couchrests_by_timestamp')
rows = data['rows']
post = Post.new(rows.first)
post.attributes
=> {:tags=>"one, two, three", :updated_at=>Tue Jun 09 14:45:00 +0200 2009,
:author=>nil, :title=>"First Post",
:created_at=>Tue Jun 09 14:45:00 +0200 2009,
:body=>"This is the first post. This is the [...] first post. "}
post.fulltext_attributes
=> {:title=>"First Post", :author=>nil,
:created_at=>Tue Jun 09 14:45:00 +0200 2009
:body=>"This is the first post. This is the [...] first post. "}
post.sphinx_id
=> "921744775"
post.id
=> "Post-921744775"
Instance Method Summary collapse
-
#fulltext_attributes ⇒ Object
Returns a Hash of all attributes allowed to be indexed.
-
#sphinx_id ⇒ Object
Returns the numeric part of the document ID (compatible to Sphinx).
Instance Method Details
#fulltext_attributes ⇒ Object
Returns a Hash of all attributes allowed to be indexed. As a side effect it sets the fulltext_keys variable if still blank or empty.
41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/mixins/properties.rb', line 41 def fulltext_attributes clas = self.class if not clas.fulltext_keys or clas.fulltext_keys.empty? clas.fulltext_keys = self.attributes.collect { |k,v| k.intern } end return self.attributes.reject do |k, v| not (clas.fulltext_keys.include? k.intern) end end |
#sphinx_id ⇒ Object
Returns the numeric part of the document ID (compatible to Sphinx).
55 56 57 58 59 60 61 |
# File 'lib/mixins/properties.rb', line 55 def sphinx_id if (match = self.id.match(/#{self.class}-([0-9]+)/)) return match[1] else return nil end end |