Arun Agrawal’s Blog

Ruby on Rails Developer

Creating Documents, MongoDB — 2

Inserts are the basic method for adding data to MongoDB. To insert a document into a collection, use the collection’s insert method:

 > db.foo.insert({"bar" : "baz"})

Tags:

MongoDB — 1

Hi,

I have started using MongoDB for my projects.

MongoDB is a powerful, flexible, and scalable data store. It combines the ability to scale out with many of the most useful features of relational databases, such as secondary indexes, range queries, and sorting. MongoDB has built-in support for MapReduce-style aggregation and geospatial indexes

Rake Migration: Track Rake Tasks With Versions

I have started working on a plugin which helps rails projects to maintain the list of rake tasks. We are working on a project there are four to six teams at different geo-locations Bangalore, Kolkata, Edmonton etc.For the same project we have different environments like Developemnt, Testing, Staging, QA, QA2, Beta etc.All teams are working with new features, as well as bug fixes. Many times we found a situation that a specific rake task should be run on a specific environment to fix the data. A lot of time team members forgot to shoot a mail and tell every team about a rake task which will fix a bug on specific environment. As other people update code base and start using the application they got stuck and it take a lot of time to resolve the issue that a specific task was not run because team did not get any information as such. To resolve this issue we got a idea form rake tasks to migrate database (db:migrate). So if we can manage rake tasks with versions and if we can keep track of tasks those have been run, and yet to run on system. One can generate a ruby file write there any ruby code or invoke any rake task, and upload to repository other people only take update from repo and run a simple commend and the system will update. Here we don’t have to worry to inform everybody about new task to fix bug or update system. Here is the URL for plugin http://github.com/vatrai/rake_migration By using generators one can generate blank ruby files prefix with time-stamped version.  Version helps to keep track of tasks that are Runyet to Run on the system. One can specify Rails environment in ruby files, specify what data fix should be run on a specified environment using simple if condition. To generate simple ruby file use: ruby script/generate rake_migration <file_name> This command creates a blank ruby file in {RAILS_ROOT}/rake/migrate directory.  Write ruby code or invoke rake task in the generated ruby file. To run generated files run rake command: {RAILS_ROOT} rake rake_migration:migrate This command runs remaining(yet to run) ruby files in {RAILS_ROOT}/rake/migrate and saves version in rake_migrations table in database.

Method Visibility Public, Protected, Private

Instance methods may be publicprivate, or protected.

Methods are normally public unless they are explicitly declared to be private or protected. One exception is the initialize method, which is always implicitly private. Another exception is any “global” method declared outside of a class definition—those methods are defined as private instance methods of Object. A public method can be invoked from anywhere—there are no restrictions on its use.

A private method is internal to the implementation of a class, and it can only be called by other instance methods of the class (or, as we’ll see later, its subclasses). Private methods are implicitly invoked on self, and may not be explicitly invoked on an object. If m is a private method, then you must invoke it in functional style as m. You cannot write o.m or even self.m.

A protected method is like a private method in that it can only be invoked from within the implementation of a class or its subclasses. It differs from a private method in that it may be explicitly invoked on any instance of the class, and it is not restricted to implicit invocation on self. A protected method can be used, for example, to define an accessor that allows instances of a class to share internal state with each other, but does not allow users of the class to access that state.