This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ bin/mmconsole | |
ruby-1.8.7-p299 > require 'rubygems' # or try to define a MM class | |
NameError: uninitialized constant ActiveModel::Naming | |
from ~/.rvm/gems/ruby-1.8.7-p299@mmtest/gems/activemodel-3.0.4/lib/active_model/translation.rb:24 | |
from ./bin/../lib/mongo_mapper/translation.rb:4 | |
from ~/.rvm/gems/ruby-1.8.7-p299@mmtest/gems/activesupport-3.0.4/lib/active_support/core_ext/module/introspection.rb:70:in `const_get' | |
from ~/.rvm/gems/ruby-1.8.7-p299@mmtest/gems/activesupport-3.0.4/lib/active_support/core_ext/module/introspection.rb:70:in `local_constants' | |
from ~/.rvm/gems/ruby-1.8.7-p299@mmtest/gems/activesupport-3.0.4/lib/active_support/core_ext/module/introspection.rb:70:in `each' | |
from ~/.rvm/gems/ruby-1.8.7-p299@mmtest/gems/activesupport-3.0.4/lib/active_support/core_ext/module/introspection.rb:70:in `local_constants' | |
from ~/.rvm/gems/ruby-1.8.7-p299@mmtest/gems/activesupport-3.0.4/lib/active_support/core_ext/module/introspection.rb:68:in `each' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def build_indexes! | |
ensure_index [["parent_id", Mongo::ASCENDING]] | |
ensure_index [["place_type", Mongo::ASCENDING], ["name", Mongo::ASCENDING]] | |
ensure_index [["ancestor_ids", Mongo::ASCENDING], ["place_type", Mongo::ASCENDING]] | |
end | |
def ensure_index(index_keys) | |
puts "Ensuring index on #{index_keys.map{|i| i[0]}.join(', ')}..." | |
collection.ensure_index index_keys | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ENV['MONGOHQ_URL'] = 'mongodb://localhost/sushi' | |
MongoMapper.database = "mes-#{Rails.env}" | |
# if ENV['MONGOHQ_URL'] | |
# MongoMapper.config = {RAILS_ENV => {'uri' => ENV['MONGOHQ_URL']}} | |
# MongoMapper.connect(RAILS_ENV) | |
# end | |
if Rails.env == "development" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class GlobalStats | |
include MongoMapper::Document | |
key :attempts, Attempts | |
end | |
class Attempts | |
attr_accessor :total, :hours | |
def self.to_mongo(attempts) | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Commentable | |
include MongoMapper::Document | |
many :comments, :as => :commentable | |
end | |
class Article < Commentable | |
end | |
class Product < Commentable | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Person | |
include MongoMapper::Document | |
end | |
class Registree < Person | |
key :in_wels, Boolean | |
key :in_vienna, Boolean | |
end | |
class Visitor < Registree |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Person | |
include MongoMapper::Document | |
end | |
class Registree < Person | |
key :in_wels, Boolean | |
key :in_vienna, Boolean | |
end | |
class Visitor |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Person | |
include MongoMapper::Document | |
end | |
class Registree < Person | |
key :in_wels, Boolean | |
key :in_vienna, Boolean | |
end | |
class Visitor |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# single collection inheritance | |
# all will be stored in the Person collection in the db | |
class Person | |
include MongoMapper::Document | |
end | |
class Registree < Person | |
key :visitor, Boolean | |
scope :vistors, :visitor => true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
criteria.merge!( :_keywords => { :$in => words } ) | |
search_result = collection.map_reduce(search_map(words), search_reduce, :query => criteria) | |
def search_reduce | |
"function( key , values ){return values[0];}" | |
end | |
def search_map(words) | |
#convert words into Regex OR |