Sha256: f96ca0eca4a50ffd5d1f25398faf1011181817f845458b873c03dbc966c47630

Contents?: true

Size: 1.9 KB

Versions: 2

Compression:

Stored size: 1.9 KB

Contents

# Extensions for MongoMapper

## Simultaneous use of multiple databases

    MongoMapper.db_config = {
      'default' => {'name' => "default_test"}
      'global' => {'name' => 'global_test'},      
    }

    # Comment will be connected to :default database
    module Comment
      belongs_to :user
    end

    # User will be connected to :global database
    module User
      use_database :global
      
      has_many :comments
    end
    
## Migrations

    # Works with multiple databases, support versions
    Migration.define :default, 1 do |m|
      m.up{Sample.create name: 'name'}
      m.down{Sample.destroy_all}
    end
    
    # Tell it database and version, and it's smart enough to figure out all needed :up or :down
    Migration.update(:default, 1)
    

## Custom Scope
    :with_scope, :default_scope, :with_exclusive_scope, see spec for details.
    
## Counter Cache

    class Comment
      belongs_to :post, counter_cache: true
    end
    
    Post.comments_count
    
## Attribute Converters

For editing complex objects in forms:

    class Post
      key :tags, Array, as_string: :line
    end
    
    @post.tags_as_string = "personal, article"
    @post.tags                                  # => ['personal', 'article']
    @post.tags_as_string                        # => "personal, article"
    
## Handy upserts

    @post.upsert! :$inc => {comments_count: 1}
    
## CarrierWave integration

File attachments (stored on File System, S3, MongoDB-GridFS)

    class User
      file_key :avatar, AvatarUploader
    end
    
## more

Attribute Cache, Spec Helpers (auto-clean db before each test).

# Installation

    gem install 'mongo_mapper_ext'
    
    require 'mongo_mapper_ext/mongo_mapper'
        
    # support for CarrierWave is optional
    # require 'mongo_mapper_ext/carrier_wave'

# License

Copyright (c) Alexey Petrushin [http://4ire.net](http://4ire.net), released under the MIT license.

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
mongo_mapper_ext-0.2.6 readme.md
mongo_mapper_ext-0.2.5 readme.md