mr_mongo 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +19 -0
- data/.rspec +1 -0
- data/.travis.yml +13 -0
- data/ChangeLog.md +7 -0
- data/Gemfile +4 -0
- data/Guardfile +9 -0
- data/LICENSE.txt +22 -0
- data/README.md +73 -0
- data/Rakefile +1 -0
- data/bin/mr_mongo +4 -0
- data/examples/word_count.rb +22 -0
- data/lib/mr_mongo/application.rb +53 -0
- data/lib/mr_mongo/context.rb +9 -0
- data/lib/mr_mongo/dsl.rb +19 -0
- data/lib/mr_mongo/loader.rb +27 -0
- data/lib/mr_mongo/map_reduce.rb +51 -0
- data/lib/mr_mongo/version.rb +3 -0
- data/lib/mr_mongo.rb +10 -0
- data/mr_mongo.gemspec +32 -0
- data/spec/fixtures/fixture_dsl.rb +9 -0
- data/spec/spec_helper.rb +20 -0
- data/spec/unit/lib/mr_mongo/dsl_spec.rb +24 -0
- data/spec/unit/lib/mr_mongo/loader_spec.rb +43 -0
- data/spec/unit/lib/mr_mongo/map_reduce_spec.rb +87 -0
- metadata +242 -0
    
        data/.gitignore
    ADDED
    
    
    
        data/.rspec
    ADDED
    
    | @@ -0,0 +1 @@ | |
| 1 | 
            +
            -fd -c --require=spec_helper
         | 
    
        data/.travis.yml
    ADDED
    
    
    
        data/ChangeLog.md
    ADDED
    
    
    
        data/Gemfile
    ADDED
    
    
    
        data/Guardfile
    ADDED
    
    
    
        data/LICENSE.txt
    ADDED
    
    | @@ -0,0 +1,22 @@ | |
| 1 | 
            +
            Copyright (c) 2013 Yuya Takeyama
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            MIT License
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            Permission is hereby granted, free of charge, to any person obtaining
         | 
| 6 | 
            +
            a copy of this software and associated documentation files (the
         | 
| 7 | 
            +
            "Software"), to deal in the Software without restriction, including
         | 
| 8 | 
            +
            without limitation the rights to use, copy, modify, merge, publish,
         | 
| 9 | 
            +
            distribute, sublicense, and/or sell copies of the Software, and to
         | 
| 10 | 
            +
            permit persons to whom the Software is furnished to do so, subject to
         | 
| 11 | 
            +
            the following conditions:
         | 
| 12 | 
            +
             | 
| 13 | 
            +
            The above copyright notice and this permission notice shall be
         | 
| 14 | 
            +
            included in all copies or substantial portions of the Software.
         | 
| 15 | 
            +
             | 
| 16 | 
            +
            THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
         | 
| 17 | 
            +
            EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
         | 
| 18 | 
            +
            MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
         | 
| 19 | 
            +
            NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
         | 
| 20 | 
            +
            LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
         | 
| 21 | 
            +
            OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
         | 
| 22 | 
            +
            WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
         | 
    
        data/README.md
    ADDED
    
    | @@ -0,0 +1,73 @@ | |
| 1 | 
            +
            # Mr. Mongo
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            [](https://travis-ci.org/yuya-takeyama/mr_mongo)
         | 
| 4 | 
            +
            [](https://coveralls.io/r/yuya-takeyama/mr_mongo)
         | 
| 5 | 
            +
             | 
| 6 | 
            +
            MapReduce framework for MongoDB using Ruby DSL
         | 
| 7 | 
            +
             | 
| 8 | 
            +
            ## Installation
         | 
| 9 | 
            +
             | 
| 10 | 
            +
            Add this line to your application's Gemfile:
         | 
| 11 | 
            +
             | 
| 12 | 
            +
                gem 'mr_mongo'
         | 
| 13 | 
            +
             | 
| 14 | 
            +
            And then execute:
         | 
| 15 | 
            +
             | 
| 16 | 
            +
                $ bundle
         | 
| 17 | 
            +
             | 
| 18 | 
            +
            Or install it yourself as:
         | 
| 19 | 
            +
             | 
| 20 | 
            +
                $ gem install mr_mongo
         | 
| 21 | 
            +
             | 
| 22 | 
            +
            ## Usage
         | 
| 23 | 
            +
             | 
| 24 | 
            +
            ### mr_mongo command
         | 
| 25 | 
            +
             | 
| 26 | 
            +
            ```
         | 
| 27 | 
            +
            $ bundle exec mr_mongo
         | 
| 28 | 
            +
            Commands:
         | 
| 29 | 
            +
              mr_mongo exec            # executes MapReduce
         | 
| 30 | 
            +
              mr_mongo exec_on_memory  # executes MapReduce on memory
         | 
| 31 | 
            +
              mr_mongo help [COMMAND]  # Describe available commands or one specific command
         | 
| 32 | 
            +
            ```
         | 
| 33 | 
            +
             | 
| 34 | 
            +
            *NOTICE*
         | 
| 35 | 
            +
             | 
| 36 | 
            +
            The result of exec_on_memory may be massive, so it's preferable to use for small collections as testing.
         | 
| 37 | 
            +
             | 
| 38 | 
            +
            ### Defining MapReduce job using DSL
         | 
| 39 | 
            +
             | 
| 40 | 
            +
            Following is word-count example using Mr. Mongo DSL
         | 
| 41 | 
            +
             | 
| 42 | 
            +
            ```ruby
         | 
| 43 | 
            +
            set :collection, 'texts'
         | 
| 44 | 
            +
            set :out, {replace: 'word_counts'}
         | 
| 45 | 
            +
             | 
| 46 | 
            +
            __END__
         | 
| 47 | 
            +
             | 
| 48 | 
            +
            @@ map
         | 
| 49 | 
            +
            function () {
         | 
| 50 | 
            +
              this.text.split(/\s+/).forEach(function (word) {
         | 
| 51 | 
            +
                emit(word, {count: 1});
         | 
| 52 | 
            +
              });
         | 
| 53 | 
            +
            }
         | 
| 54 | 
            +
             | 
| 55 | 
            +
            @@ reduce
         | 
| 56 | 
            +
            function (key, values) {
         | 
| 57 | 
            +
              var count = 0;
         | 
| 58 | 
            +
             | 
| 59 | 
            +
              values.forEach(function (value) {
         | 
| 60 | 
            +
                count += value.count;
         | 
| 61 | 
            +
              });
         | 
| 62 | 
            +
             | 
| 63 | 
            +
              return {count: count};
         | 
| 64 | 
            +
            }
         | 
| 65 | 
            +
            ```
         | 
| 66 | 
            +
             | 
| 67 | 
            +
            ## Contributing
         | 
| 68 | 
            +
             | 
| 69 | 
            +
            1. Fork it
         | 
| 70 | 
            +
            2. Create your feature branch (`git checkout -b my-new-feature`)
         | 
| 71 | 
            +
            3. Commit your changes (`git commit -am 'Add some feature'`)
         | 
| 72 | 
            +
            4. Push to the branch (`git push origin my-new-feature`)
         | 
| 73 | 
            +
            5. Create new Pull Request
         | 
    
        data/Rakefile
    ADDED
    
    | @@ -0,0 +1 @@ | |
| 1 | 
            +
            require "bundler/gem_tasks"
         | 
    
        data/bin/mr_mongo
    ADDED
    
    
| @@ -0,0 +1,22 @@ | |
| 1 | 
            +
            set :collection, 'texts'
         | 
| 2 | 
            +
            set :out, {replace: 'word_counts'}
         | 
| 3 | 
            +
             | 
| 4 | 
            +
            __END__
         | 
| 5 | 
            +
             | 
| 6 | 
            +
            @@ map
         | 
| 7 | 
            +
            function () {
         | 
| 8 | 
            +
              this.text.split(/\s+/).forEach(function (word) {
         | 
| 9 | 
            +
                emit(word, {count: 1});
         | 
| 10 | 
            +
              });
         | 
| 11 | 
            +
            }
         | 
| 12 | 
            +
             | 
| 13 | 
            +
            @@ reduce
         | 
| 14 | 
            +
            function (key, values) {
         | 
| 15 | 
            +
              var count = 0;
         | 
| 16 | 
            +
             | 
| 17 | 
            +
              values.forEach(function (value) {
         | 
| 18 | 
            +
                count += value.count;
         | 
| 19 | 
            +
              });
         | 
| 20 | 
            +
             | 
| 21 | 
            +
              return {count: count};
         | 
| 22 | 
            +
            }
         | 
| @@ -0,0 +1,53 @@ | |
| 1 | 
            +
            require 'thor'
         | 
| 2 | 
            +
            require 'mongo'
         | 
| 3 | 
            +
            require 'pp'
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            module MrMongo
         | 
| 6 | 
            +
              class Application < ::Thor
         | 
| 7 | 
            +
                DEFAULT_URI = 'mongodb://localhost:27017/test'
         | 
| 8 | 
            +
             | 
| 9 | 
            +
                desc 'exec', 'executes MapReduce'
         | 
| 10 | 
            +
                method_option :db, default: DEFAULT_URI
         | 
| 11 | 
            +
                def exec(*files)
         | 
| 12 | 
            +
                  files.each do |file|
         | 
| 13 | 
            +
                    puts "Executing #{file}..."
         | 
| 14 | 
            +
                    pp loader.load(file).exec
         | 
| 15 | 
            +
                    puts
         | 
| 16 | 
            +
                  end
         | 
| 17 | 
            +
             | 
| 18 | 
            +
                  puts "Finished MapReduce execution."
         | 
| 19 | 
            +
                end
         | 
| 20 | 
            +
             | 
| 21 | 
            +
                desc 'exec_on_memory', 'executes MapReduce on memory'
         | 
| 22 | 
            +
                method_option :db, default: DEFAULT_URI
         | 
| 23 | 
            +
                def exec_on_memory(*files)
         | 
| 24 | 
            +
                  files.each do |file|
         | 
| 25 | 
            +
                    puts "Executing #{file} on memory..."
         | 
| 26 | 
            +
                    pp loader.load(file).exec_on_memory
         | 
| 27 | 
            +
                    puts
         | 
| 28 | 
            +
                  end
         | 
| 29 | 
            +
             | 
| 30 | 
            +
                  puts "Finished MapReduce execution (on memory)."
         | 
| 31 | 
            +
                end
         | 
| 32 | 
            +
             | 
| 33 | 
            +
                private
         | 
| 34 | 
            +
                def loader
         | 
| 35 | 
            +
                  Loader.new(context)
         | 
| 36 | 
            +
                end
         | 
| 37 | 
            +
             | 
| 38 | 
            +
                def context
         | 
| 39 | 
            +
                  Context.new(db: database)
         | 
| 40 | 
            +
                end
         | 
| 41 | 
            +
             | 
| 42 | 
            +
                def database
         | 
| 43 | 
            +
                  path = URI.parse(options[:db]).path
         | 
| 44 | 
            +
                  database_name = if path =~ %r{^/([^/]+)}
         | 
| 45 | 
            +
                    $1
         | 
| 46 | 
            +
                  else
         | 
| 47 | 
            +
                    'test'
         | 
| 48 | 
            +
                  end
         | 
| 49 | 
            +
             | 
| 50 | 
            +
                  ::Mongo::MongoClient.from_uri(options[:db]).db(database_name)
         | 
| 51 | 
            +
                end
         | 
| 52 | 
            +
              end
         | 
| 53 | 
            +
            end
         | 
    
        data/lib/mr_mongo/dsl.rb
    ADDED
    
    | @@ -0,0 +1,19 @@ | |
| 1 | 
            +
            module MrMongo
         | 
| 2 | 
            +
              class Dsl
         | 
| 3 | 
            +
                attr_reader :map_reduce
         | 
| 4 | 
            +
             | 
| 5 | 
            +
                def initialize(context)
         | 
| 6 | 
            +
                  @map_reduce = MapReduce.new(context)
         | 
| 7 | 
            +
                end
         | 
| 8 | 
            +
             | 
| 9 | 
            +
                def parse(&block)
         | 
| 10 | 
            +
                  instance_eval &block
         | 
| 11 | 
            +
                  
         | 
| 12 | 
            +
                  self
         | 
| 13 | 
            +
                end
         | 
| 14 | 
            +
             | 
| 15 | 
            +
                def set(key, value = true)
         | 
| 16 | 
            +
                  @map_reduce.send("#{key}=", value)
         | 
| 17 | 
            +
                end
         | 
| 18 | 
            +
              end
         | 
| 19 | 
            +
            end
         | 
| @@ -0,0 +1,27 @@ | |
| 1 | 
            +
            require 'inline_template_loader'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            module MrMongo
         | 
| 4 | 
            +
              class Loader
         | 
| 5 | 
            +
                def initialize(context)
         | 
| 6 | 
            +
                  @context = context
         | 
| 7 | 
            +
                end
         | 
| 8 | 
            +
             | 
| 9 | 
            +
                def load(file)
         | 
| 10 | 
            +
                  dsl_script = ::File.read(file).sub!(/^__END__\n.*\Z/m, '')
         | 
| 11 | 
            +
             | 
| 12 | 
            +
                  map_reduce = load_from_string(dsl_script)
         | 
| 13 | 
            +
             | 
| 14 | 
            +
                  InlineTemplateLoader.load(file).each do |key, val|
         | 
| 15 | 
            +
                    map_reduce.send("#{key}=".to_sym, val)
         | 
| 16 | 
            +
                  end
         | 
| 17 | 
            +
             | 
| 18 | 
            +
                  map_reduce
         | 
| 19 | 
            +
                end
         | 
| 20 | 
            +
             | 
| 21 | 
            +
                def load_from_string(dsl_script, file = "(Mr. Mongo DSL)")
         | 
| 22 | 
            +
                  dsl = Dsl.new(@context)
         | 
| 23 | 
            +
             | 
| 24 | 
            +
                  eval "dsl.parse {\n" + dsl_script + "\n}.map_reduce", binding, file, 0
         | 
| 25 | 
            +
                end
         | 
| 26 | 
            +
              end
         | 
| 27 | 
            +
            end
         | 
| @@ -0,0 +1,51 @@ | |
| 1 | 
            +
            module MrMongo
         | 
| 2 | 
            +
              class MapReduce
         | 
| 3 | 
            +
                attr_accessor :collection, :map, :reduce, :out, :query, :sort, :limit,
         | 
| 4 | 
            +
                  :finalize, :scope, :js_mode, :verbose
         | 
| 5 | 
            +
             | 
| 6 | 
            +
                def initialize(context)
         | 
| 7 | 
            +
                  @context = context
         | 
| 8 | 
            +
                end
         | 
| 9 | 
            +
             | 
| 10 | 
            +
                def to_options
         | 
| 11 | 
            +
                  options = {}
         | 
| 12 | 
            +
             | 
| 13 | 
            +
                  options[:query]    = @query    if defined?(@query)
         | 
| 14 | 
            +
                  options[:sort]     = @sort     if defined?(@sort)
         | 
| 15 | 
            +
                  options[:limit]    = @limit    if defined?(@limit)
         | 
| 16 | 
            +
                  options[:finalize] = @finalize if defined?(@finalize)
         | 
| 17 | 
            +
                  options[:out]      = @out      if defined?(@out)
         | 
| 18 | 
            +
                  options[:verbose]  = @verbose  if defined?(@verbose)
         | 
| 19 | 
            +
             | 
| 20 | 
            +
                  options[:raw] = true if defined?(@out) and @out.is_a?(::Hash) and @out[:inline]
         | 
| 21 | 
            +
             | 
| 22 | 
            +
                  options
         | 
| 23 | 
            +
                end
         | 
| 24 | 
            +
             | 
| 25 | 
            +
                def exec
         | 
| 26 | 
            +
                  exec_with_options(to_options)
         | 
| 27 | 
            +
                end
         | 
| 28 | 
            +
             | 
| 29 | 
            +
                def exec_on_memory
         | 
| 30 | 
            +
                  options = to_options
         | 
| 31 | 
            +
                  options[:out] = {inline: true}
         | 
| 32 | 
            +
                  options[:raw] = true
         | 
| 33 | 
            +
             | 
| 34 | 
            +
                  exec_with_options(options)
         | 
| 35 | 
            +
                end
         | 
| 36 | 
            +
             | 
| 37 | 
            +
                def insert_into_collection(*args)
         | 
| 38 | 
            +
                  mongo_collection.send(:insert, *args)
         | 
| 39 | 
            +
                end
         | 
| 40 | 
            +
                alias_method :insert, :insert_into_collection
         | 
| 41 | 
            +
             | 
| 42 | 
            +
                private
         | 
| 43 | 
            +
                def exec_with_options(options)
         | 
| 44 | 
            +
                  mongo_collection.map_reduce(@map, @reduce, options)
         | 
| 45 | 
            +
                end
         | 
| 46 | 
            +
             | 
| 47 | 
            +
                def mongo_collection
         | 
| 48 | 
            +
                  @context.db.collection(@collection)
         | 
| 49 | 
            +
                end
         | 
| 50 | 
            +
              end
         | 
| 51 | 
            +
            end
         | 
    
        data/lib/mr_mongo.rb
    ADDED
    
    
    
        data/mr_mongo.gemspec
    ADDED
    
    | @@ -0,0 +1,32 @@ | |
| 1 | 
            +
            # coding: utf-8
         | 
| 2 | 
            +
            lib = File.expand_path('../lib', __FILE__)
         | 
| 3 | 
            +
            $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
         | 
| 4 | 
            +
            require 'mr_mongo/version'
         | 
| 5 | 
            +
             | 
| 6 | 
            +
            Gem::Specification.new do |spec|
         | 
| 7 | 
            +
              spec.name          = "mr_mongo"
         | 
| 8 | 
            +
              spec.version       = MrMongo::VERSION
         | 
| 9 | 
            +
              spec.authors       = ["Yuya Takeyama"]
         | 
| 10 | 
            +
              spec.email         = ["sign.of.the.wolf.pentagram@gmail.com"]
         | 
| 11 | 
            +
              spec.description   = %q{MapReduce framework for MongoDB using Ruby DSL}
         | 
| 12 | 
            +
              spec.summary       = %q{MapReduce framework for MongoDB using Ruby DSL}
         | 
| 13 | 
            +
              spec.homepage      = ""
         | 
| 14 | 
            +
              spec.license       = "MIT"
         | 
| 15 | 
            +
             | 
| 16 | 
            +
              spec.files         = `git ls-files`.split($/)
         | 
| 17 | 
            +
              spec.executables   = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
         | 
| 18 | 
            +
              spec.test_files    = spec.files.grep(%r{^(test|spec|features)/})
         | 
| 19 | 
            +
              spec.require_paths = ["lib"]
         | 
| 20 | 
            +
             | 
| 21 | 
            +
              spec.add_dependency "mongo", "~> 1.8.4"
         | 
| 22 | 
            +
              spec.add_dependency "bson_ext", "~> 1.8.4"
         | 
| 23 | 
            +
              spec.add_dependency "thor", "~> 0.18.1"
         | 
| 24 | 
            +
              spec.add_dependency "inline_template_loader", "~> 0.3.0"
         | 
| 25 | 
            +
             | 
| 26 | 
            +
              spec.add_development_dependency "bundler", "~> 1.3"
         | 
| 27 | 
            +
              spec.add_development_dependency "rake"
         | 
| 28 | 
            +
              spec.add_development_dependency "rspec", "~> 2.13.0"
         | 
| 29 | 
            +
              spec.add_development_dependency "guard-rspec", "~> 2.5.2"
         | 
| 30 | 
            +
              spec.add_development_dependency "rb-fsevent", "~> 0.9.1"
         | 
| 31 | 
            +
              spec.add_development_dependency "coveralls", "~> 0.6.4"
         | 
| 32 | 
            +
            end
         | 
    
        data/spec/spec_helper.rb
    ADDED
    
    | @@ -0,0 +1,20 @@ | |
| 1 | 
            +
            require 'coveralls'
         | 
| 2 | 
            +
            Coveralls.wear!
         | 
| 3 | 
            +
            require 'mr_mongo'
         | 
| 4 | 
            +
            require 'mongo'
         | 
| 5 | 
            +
             | 
| 6 | 
            +
            RSpec.configure do |c|
         | 
| 7 | 
            +
              c.filter_run_excluding mongo: true unless ENV['MR_MONGO_RUN_ALL_TESTS']
         | 
| 8 | 
            +
            end
         | 
| 9 | 
            +
             | 
| 10 | 
            +
            def testing_connection
         | 
| 11 | 
            +
              ::Mongo::Connection.new('localhost')
         | 
| 12 | 
            +
            end
         | 
| 13 | 
            +
             | 
| 14 | 
            +
            def testing_database
         | 
| 15 | 
            +
              testing_connection.db('mr_mongo_test')
         | 
| 16 | 
            +
            end
         | 
| 17 | 
            +
             | 
| 18 | 
            +
            def drop_testing_database
         | 
| 19 | 
            +
              testing_connection.drop_database('mr_mongo_test')
         | 
| 20 | 
            +
            end
         | 
| @@ -0,0 +1,24 @@ | |
| 1 | 
            +
            module MrMongo
         | 
| 2 | 
            +
              describe Dsl do
         | 
| 3 | 
            +
                let(:context) { Context.new }
         | 
| 4 | 
            +
                let(:dsl) { Dsl.new(context) }
         | 
| 5 | 
            +
             | 
| 6 | 
            +
                describe '#set' do
         | 
| 7 | 
            +
                  subject { dsl.map_reduce.verbose }
         | 
| 8 | 
            +
             | 
| 9 | 
            +
                  context 'one is passed as argument' do
         | 
| 10 | 
            +
                    before { dsl.set :verbose, 1 }
         | 
| 11 | 
            +
             | 
| 12 | 
            +
                    it 'should set its argument to MapReduce object' do
         | 
| 13 | 
            +
                      should eq(1)
         | 
| 14 | 
            +
                    end
         | 
| 15 | 
            +
                  end
         | 
| 16 | 
            +
             | 
| 17 | 
            +
                  context 'no arguments are passed' do
         | 
| 18 | 
            +
                    before { dsl.set :verbose }
         | 
| 19 | 
            +
             | 
| 20 | 
            +
                    it { should be_true }
         | 
| 21 | 
            +
                  end
         | 
| 22 | 
            +
                end
         | 
| 23 | 
            +
              end
         | 
| 24 | 
            +
            end
         | 
| @@ -0,0 +1,43 @@ | |
| 1 | 
            +
            require 'spec_helper'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            module MrMongo
         | 
| 4 | 
            +
              describe Loader do
         | 
| 5 | 
            +
                let(:loader) { Loader.new(Context.new) }
         | 
| 6 | 
            +
             | 
| 7 | 
            +
                describe '#load_from_string' do
         | 
| 8 | 
            +
                  subject { loader.load_from_string(dsl_script) }
         | 
| 9 | 
            +
             | 
| 10 | 
            +
                  context 'some parameters are set' do
         | 
| 11 | 
            +
                    let(:dsl_script) do
         | 
| 12 | 
            +
                      <<-EOS
         | 
| 13 | 
            +
                        set :collection, "foo"
         | 
| 14 | 
            +
                        set :out, "bar"
         | 
| 15 | 
            +
                        set :verbose, true
         | 
| 16 | 
            +
                      EOS
         | 
| 17 | 
            +
                    end
         | 
| 18 | 
            +
             | 
| 19 | 
            +
                    its(:collection) { should eq('foo') }
         | 
| 20 | 
            +
                    its(:out)        { should eq('bar') }
         | 
| 21 | 
            +
                    its(:verbose)    { should be_true }
         | 
| 22 | 
            +
                  end
         | 
| 23 | 
            +
             | 
| 24 | 
            +
                  context 'no parameters are set' do
         | 
| 25 | 
            +
                    let(:dsl_script) { '' }
         | 
| 26 | 
            +
             | 
| 27 | 
            +
                    its(:collection) { should be_nil }
         | 
| 28 | 
            +
                    its(:out)        { should be_nil }
         | 
| 29 | 
            +
                    its(:verbose)    { should be_nil }
         | 
| 30 | 
            +
                  end
         | 
| 31 | 
            +
                end
         | 
| 32 | 
            +
             | 
| 33 | 
            +
                describe '#load' do
         | 
| 34 | 
            +
                  subject { loader.load(File.expand_path(File.join(__FILE__, '../../../../fixtures/fixture_dsl.rb'))) }
         | 
| 35 | 
            +
             | 
| 36 | 
            +
                  its(:collection) { should eq('foo') }
         | 
| 37 | 
            +
                  its(:out)        { should eq('bar') }
         | 
| 38 | 
            +
                  its(:verbose)    { should be_true }
         | 
| 39 | 
            +
                  its(:map)        { should eq("function () { emit(this.id, this.count); }\n") }
         | 
| 40 | 
            +
                  its(:reduce)     { should eq("function (key, values) { return 0; }\n") }
         | 
| 41 | 
            +
                end
         | 
| 42 | 
            +
              end
         | 
| 43 | 
            +
            end
         | 
| @@ -0,0 +1,87 @@ | |
| 1 | 
            +
            module MrMongo
         | 
| 2 | 
            +
              describe MapReduce do
         | 
| 3 | 
            +
                let(:context) { Context.new(db: testing_database) }
         | 
| 4 | 
            +
                let(:map_reduce) { MapReduce.new(context) }
         | 
| 5 | 
            +
             | 
| 6 | 
            +
                describe '#to_options' do
         | 
| 7 | 
            +
                  subject { map_reduce.to_options }
         | 
| 8 | 
            +
             | 
| 9 | 
            +
                  context 'some options are specified' do
         | 
| 10 | 
            +
                    before do
         | 
| 11 | 
            +
                      map_reduce.query   = {foo: "bar"}
         | 
| 12 | 
            +
                      map_reduce.limit   = 50
         | 
| 13 | 
            +
                      map_reduce.verbose = true
         | 
| 14 | 
            +
                    end
         | 
| 15 | 
            +
             | 
| 16 | 
            +
                    it { should eq({query: {foo: "bar"}, limit: 50, verbose: true}) }
         | 
| 17 | 
            +
                  end
         | 
| 18 | 
            +
             | 
| 19 | 
            +
                  context 'out is inline' do
         | 
| 20 | 
            +
                    before do
         | 
| 21 | 
            +
                      map_reduce.out = {inline: true}
         | 
| 22 | 
            +
                    end
         | 
| 23 | 
            +
             | 
| 24 | 
            +
                    it { should eq({out: {inline: true}, raw: true}) }
         | 
| 25 | 
            +
                  end
         | 
| 26 | 
            +
                end
         | 
| 27 | 
            +
             | 
| 28 | 
            +
                describe 'MapReduce excution', mongo: true do
         | 
| 29 | 
            +
                  let(:expected) do
         | 
| 30 | 
            +
                    [
         | 
| 31 | 
            +
                      {'_id' => 'be', 'value' => 2.0},
         | 
| 32 | 
            +
                      {'_id' => 'not', 'value' => 1.0},
         | 
| 33 | 
            +
                      {'_id' => 'or', 'value' => 1.0},
         | 
| 34 | 
            +
                      {'_id' => 'to', 'value' => 2.0},
         | 
| 35 | 
            +
                    ]
         | 
| 36 | 
            +
                  end
         | 
| 37 | 
            +
             | 
| 38 | 
            +
                  shared_examples_for 'executes MapReduce correctly' do
         | 
| 39 | 
            +
                    it { should eq(expected) }
         | 
| 40 | 
            +
                  end
         | 
| 41 | 
            +
             | 
| 42 | 
            +
                  before do
         | 
| 43 | 
            +
                    map_reduce.collection = 'foo'
         | 
| 44 | 
            +
             | 
| 45 | 
            +
                    map_reduce.insert({word: 'to'})
         | 
| 46 | 
            +
                    map_reduce.insert({word: 'be'})
         | 
| 47 | 
            +
                    map_reduce.insert({word: 'or'})
         | 
| 48 | 
            +
                    map_reduce.insert({word: 'not'})
         | 
| 49 | 
            +
                    map_reduce.insert({word: 'to'})
         | 
| 50 | 
            +
                    map_reduce.insert({word: 'be'})
         | 
| 51 | 
            +
             | 
| 52 | 
            +
                    map_reduce.map = <<-EOS
         | 
| 53 | 
            +
                      function () {
         | 
| 54 | 
            +
                        emit(this.word, 1);
         | 
| 55 | 
            +
                      }
         | 
| 56 | 
            +
                    EOS
         | 
| 57 | 
            +
                    map_reduce.reduce = <<-EOS
         | 
| 58 | 
            +
                      function (key, values) {
         | 
| 59 | 
            +
                        var count = 0;
         | 
| 60 | 
            +
             | 
| 61 | 
            +
                        values.forEach(function (value) {
         | 
| 62 | 
            +
                          count += value;
         | 
| 63 | 
            +
                        });
         | 
| 64 | 
            +
             | 
| 65 | 
            +
                        return count;
         | 
| 66 | 
            +
                      }
         | 
| 67 | 
            +
                    EOS
         | 
| 68 | 
            +
                  end
         | 
| 69 | 
            +
             | 
| 70 | 
            +
                  after { drop_testing_database }
         | 
| 71 | 
            +
             | 
| 72 | 
            +
                  describe '#exec' do
         | 
| 73 | 
            +
                    subject { map_reduce.exec.find.to_a }
         | 
| 74 | 
            +
             | 
| 75 | 
            +
                    before { map_reduce.out = {replace: 'result'} }
         | 
| 76 | 
            +
             | 
| 77 | 
            +
                    it_should_behave_like 'executes MapReduce correctly'
         | 
| 78 | 
            +
                  end
         | 
| 79 | 
            +
             | 
| 80 | 
            +
                  describe '#exec_on_memory' do
         | 
| 81 | 
            +
                    subject { map_reduce.exec_on_memory['results'] }
         | 
| 82 | 
            +
             | 
| 83 | 
            +
                    it_should_behave_like 'executes MapReduce correctly'
         | 
| 84 | 
            +
                  end
         | 
| 85 | 
            +
                end
         | 
| 86 | 
            +
              end
         | 
| 87 | 
            +
            end
         | 
    
        metadata
    ADDED
    
    | @@ -0,0 +1,242 @@ | |
| 1 | 
            +
            --- !ruby/object:Gem::Specification
         | 
| 2 | 
            +
            name: mr_mongo
         | 
| 3 | 
            +
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            +
              version: 0.0.1
         | 
| 5 | 
            +
              prerelease: 
         | 
| 6 | 
            +
            platform: ruby
         | 
| 7 | 
            +
            authors:
         | 
| 8 | 
            +
            - Yuya Takeyama
         | 
| 9 | 
            +
            autorequire: 
         | 
| 10 | 
            +
            bindir: bin
         | 
| 11 | 
            +
            cert_chain: []
         | 
| 12 | 
            +
            date: 2013-04-07 00:00:00.000000000 Z
         | 
| 13 | 
            +
            dependencies:
         | 
| 14 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 15 | 
            +
              name: mongo
         | 
| 16 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 17 | 
            +
                none: false
         | 
| 18 | 
            +
                requirements:
         | 
| 19 | 
            +
                - - ~>
         | 
| 20 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 21 | 
            +
                    version: 1.8.4
         | 
| 22 | 
            +
              type: :runtime
         | 
| 23 | 
            +
              prerelease: false
         | 
| 24 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 25 | 
            +
                none: false
         | 
| 26 | 
            +
                requirements:
         | 
| 27 | 
            +
                - - ~>
         | 
| 28 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 29 | 
            +
                    version: 1.8.4
         | 
| 30 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 31 | 
            +
              name: bson_ext
         | 
| 32 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 33 | 
            +
                none: false
         | 
| 34 | 
            +
                requirements:
         | 
| 35 | 
            +
                - - ~>
         | 
| 36 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 37 | 
            +
                    version: 1.8.4
         | 
| 38 | 
            +
              type: :runtime
         | 
| 39 | 
            +
              prerelease: false
         | 
| 40 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 41 | 
            +
                none: false
         | 
| 42 | 
            +
                requirements:
         | 
| 43 | 
            +
                - - ~>
         | 
| 44 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 45 | 
            +
                    version: 1.8.4
         | 
| 46 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 47 | 
            +
              name: thor
         | 
| 48 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 49 | 
            +
                none: false
         | 
| 50 | 
            +
                requirements:
         | 
| 51 | 
            +
                - - ~>
         | 
| 52 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 53 | 
            +
                    version: 0.18.1
         | 
| 54 | 
            +
              type: :runtime
         | 
| 55 | 
            +
              prerelease: false
         | 
| 56 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 57 | 
            +
                none: false
         | 
| 58 | 
            +
                requirements:
         | 
| 59 | 
            +
                - - ~>
         | 
| 60 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 61 | 
            +
                    version: 0.18.1
         | 
| 62 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 63 | 
            +
              name: inline_template_loader
         | 
| 64 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 65 | 
            +
                none: false
         | 
| 66 | 
            +
                requirements:
         | 
| 67 | 
            +
                - - ~>
         | 
| 68 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 69 | 
            +
                    version: 0.3.0
         | 
| 70 | 
            +
              type: :runtime
         | 
| 71 | 
            +
              prerelease: false
         | 
| 72 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 73 | 
            +
                none: false
         | 
| 74 | 
            +
                requirements:
         | 
| 75 | 
            +
                - - ~>
         | 
| 76 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 77 | 
            +
                    version: 0.3.0
         | 
| 78 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 79 | 
            +
              name: bundler
         | 
| 80 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 81 | 
            +
                none: false
         | 
| 82 | 
            +
                requirements:
         | 
| 83 | 
            +
                - - ~>
         | 
| 84 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 85 | 
            +
                    version: '1.3'
         | 
| 86 | 
            +
              type: :development
         | 
| 87 | 
            +
              prerelease: false
         | 
| 88 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 89 | 
            +
                none: false
         | 
| 90 | 
            +
                requirements:
         | 
| 91 | 
            +
                - - ~>
         | 
| 92 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 93 | 
            +
                    version: '1.3'
         | 
| 94 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 95 | 
            +
              name: rake
         | 
| 96 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 97 | 
            +
                none: false
         | 
| 98 | 
            +
                requirements:
         | 
| 99 | 
            +
                - - ! '>='
         | 
| 100 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 101 | 
            +
                    version: '0'
         | 
| 102 | 
            +
              type: :development
         | 
| 103 | 
            +
              prerelease: false
         | 
| 104 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 105 | 
            +
                none: false
         | 
| 106 | 
            +
                requirements:
         | 
| 107 | 
            +
                - - ! '>='
         | 
| 108 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 109 | 
            +
                    version: '0'
         | 
| 110 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 111 | 
            +
              name: rspec
         | 
| 112 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 113 | 
            +
                none: false
         | 
| 114 | 
            +
                requirements:
         | 
| 115 | 
            +
                - - ~>
         | 
| 116 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 117 | 
            +
                    version: 2.13.0
         | 
| 118 | 
            +
              type: :development
         | 
| 119 | 
            +
              prerelease: false
         | 
| 120 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 121 | 
            +
                none: false
         | 
| 122 | 
            +
                requirements:
         | 
| 123 | 
            +
                - - ~>
         | 
| 124 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 125 | 
            +
                    version: 2.13.0
         | 
| 126 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 127 | 
            +
              name: guard-rspec
         | 
| 128 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 129 | 
            +
                none: false
         | 
| 130 | 
            +
                requirements:
         | 
| 131 | 
            +
                - - ~>
         | 
| 132 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 133 | 
            +
                    version: 2.5.2
         | 
| 134 | 
            +
              type: :development
         | 
| 135 | 
            +
              prerelease: false
         | 
| 136 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 137 | 
            +
                none: false
         | 
| 138 | 
            +
                requirements:
         | 
| 139 | 
            +
                - - ~>
         | 
| 140 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 141 | 
            +
                    version: 2.5.2
         | 
| 142 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 143 | 
            +
              name: rb-fsevent
         | 
| 144 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 145 | 
            +
                none: false
         | 
| 146 | 
            +
                requirements:
         | 
| 147 | 
            +
                - - ~>
         | 
| 148 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 149 | 
            +
                    version: 0.9.1
         | 
| 150 | 
            +
              type: :development
         | 
| 151 | 
            +
              prerelease: false
         | 
| 152 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 153 | 
            +
                none: false
         | 
| 154 | 
            +
                requirements:
         | 
| 155 | 
            +
                - - ~>
         | 
| 156 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 157 | 
            +
                    version: 0.9.1
         | 
| 158 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 159 | 
            +
              name: coveralls
         | 
| 160 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 161 | 
            +
                none: false
         | 
| 162 | 
            +
                requirements:
         | 
| 163 | 
            +
                - - ~>
         | 
| 164 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 165 | 
            +
                    version: 0.6.4
         | 
| 166 | 
            +
              type: :development
         | 
| 167 | 
            +
              prerelease: false
         | 
| 168 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 169 | 
            +
                none: false
         | 
| 170 | 
            +
                requirements:
         | 
| 171 | 
            +
                - - ~>
         | 
| 172 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 173 | 
            +
                    version: 0.6.4
         | 
| 174 | 
            +
            description: MapReduce framework for MongoDB using Ruby DSL
         | 
| 175 | 
            +
            email:
         | 
| 176 | 
            +
            - sign.of.the.wolf.pentagram@gmail.com
         | 
| 177 | 
            +
            executables:
         | 
| 178 | 
            +
            - mr_mongo
         | 
| 179 | 
            +
            extensions: []
         | 
| 180 | 
            +
            extra_rdoc_files: []
         | 
| 181 | 
            +
            files:
         | 
| 182 | 
            +
            - .gitignore
         | 
| 183 | 
            +
            - .rspec
         | 
| 184 | 
            +
            - .travis.yml
         | 
| 185 | 
            +
            - ChangeLog.md
         | 
| 186 | 
            +
            - Gemfile
         | 
| 187 | 
            +
            - Guardfile
         | 
| 188 | 
            +
            - LICENSE.txt
         | 
| 189 | 
            +
            - README.md
         | 
| 190 | 
            +
            - Rakefile
         | 
| 191 | 
            +
            - bin/mr_mongo
         | 
| 192 | 
            +
            - examples/word_count.rb
         | 
| 193 | 
            +
            - lib/mr_mongo.rb
         | 
| 194 | 
            +
            - lib/mr_mongo/application.rb
         | 
| 195 | 
            +
            - lib/mr_mongo/context.rb
         | 
| 196 | 
            +
            - lib/mr_mongo/dsl.rb
         | 
| 197 | 
            +
            - lib/mr_mongo/loader.rb
         | 
| 198 | 
            +
            - lib/mr_mongo/map_reduce.rb
         | 
| 199 | 
            +
            - lib/mr_mongo/version.rb
         | 
| 200 | 
            +
            - mr_mongo.gemspec
         | 
| 201 | 
            +
            - spec/fixtures/fixture_dsl.rb
         | 
| 202 | 
            +
            - spec/spec_helper.rb
         | 
| 203 | 
            +
            - spec/unit/lib/mr_mongo/dsl_spec.rb
         | 
| 204 | 
            +
            - spec/unit/lib/mr_mongo/loader_spec.rb
         | 
| 205 | 
            +
            - spec/unit/lib/mr_mongo/map_reduce_spec.rb
         | 
| 206 | 
            +
            homepage: ''
         | 
| 207 | 
            +
            licenses:
         | 
| 208 | 
            +
            - MIT
         | 
| 209 | 
            +
            post_install_message: 
         | 
| 210 | 
            +
            rdoc_options: []
         | 
| 211 | 
            +
            require_paths:
         | 
| 212 | 
            +
            - lib
         | 
| 213 | 
            +
            required_ruby_version: !ruby/object:Gem::Requirement
         | 
| 214 | 
            +
              none: false
         | 
| 215 | 
            +
              requirements:
         | 
| 216 | 
            +
              - - ! '>='
         | 
| 217 | 
            +
                - !ruby/object:Gem::Version
         | 
| 218 | 
            +
                  version: '0'
         | 
| 219 | 
            +
                  segments:
         | 
| 220 | 
            +
                  - 0
         | 
| 221 | 
            +
                  hash: 1664865836217424745
         | 
| 222 | 
            +
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 223 | 
            +
              none: false
         | 
| 224 | 
            +
              requirements:
         | 
| 225 | 
            +
              - - ! '>='
         | 
| 226 | 
            +
                - !ruby/object:Gem::Version
         | 
| 227 | 
            +
                  version: '0'
         | 
| 228 | 
            +
                  segments:
         | 
| 229 | 
            +
                  - 0
         | 
| 230 | 
            +
                  hash: 1664865836217424745
         | 
| 231 | 
            +
            requirements: []
         | 
| 232 | 
            +
            rubyforge_project: 
         | 
| 233 | 
            +
            rubygems_version: 1.8.23
         | 
| 234 | 
            +
            signing_key: 
         | 
| 235 | 
            +
            specification_version: 3
         | 
| 236 | 
            +
            summary: MapReduce framework for MongoDB using Ruby DSL
         | 
| 237 | 
            +
            test_files:
         | 
| 238 | 
            +
            - spec/fixtures/fixture_dsl.rb
         | 
| 239 | 
            +
            - spec/spec_helper.rb
         | 
| 240 | 
            +
            - spec/unit/lib/mr_mongo/dsl_spec.rb
         | 
| 241 | 
            +
            - spec/unit/lib/mr_mongo/loader_spec.rb
         | 
| 242 | 
            +
            - spec/unit/lib/mr_mongo/map_reduce_spec.rb
         |