volt-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.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/README.md +7 -0
- data/Rakefile +1 -0
- data/VERSION +1 -0
- data/app/mongo/config/dependencies.rb +1 -0
- data/app/mongo/config/initializers/boot.rb +14 -0
- data/app/mongo/config/routes.rb +1 -0
- data/app/mongo/controllers/main_controller.rb +5 -0
- data/app/mongo/lib/mongo_adaptor_client.rb +74 -0
- data/app/mongo/lib/mongo_adaptor_server.rb +68 -0
- data/app/mongo/views/main/index.html +2 -0
- data/lib/volt/mongo.rb +26 -0
- data/volt-mongo.gemspec +26 -0
- metadata +100 -0
    
        checksums.yaml
    ADDED
    
    | @@ -0,0 +1,7 @@ | |
| 1 | 
            +
            ---
         | 
| 2 | 
            +
            SHA1:
         | 
| 3 | 
            +
              metadata.gz: 0288ac598fb2d952f519ad219fc91c084dc4c5c9
         | 
| 4 | 
            +
              data.tar.gz: 79ed1942819553e40fbebebfac6d600878e62d24
         | 
| 5 | 
            +
            SHA512:
         | 
| 6 | 
            +
              metadata.gz: 8f0a152b61ec012b0215684c784b3ca0e469f23a6859b3d3d569214cafbb725b054dc0f3d7f42d6300ff0a1d88e0c4868843cfde6cc636505be2cdea081e1ea7
         | 
| 7 | 
            +
              data.tar.gz: 140e76564deef0b8210ddd44359050c003628ba30e620ac1b2483fd5d84e7b7328f19e8ec6503b67af2ce06599f174fd26af97067a9cea0d42f8e6826b7ba3fb
         | 
    
        data/.gitignore
    ADDED
    
    
    
        data/Gemfile
    ADDED
    
    
    
        data/README.md
    ADDED
    
    
    
        data/Rakefile
    ADDED
    
    | @@ -0,0 +1 @@ | |
| 1 | 
            +
            require "bundler/gem_tasks"
         | 
    
        data/VERSION
    ADDED
    
    | @@ -0,0 +1 @@ | |
| 1 | 
            +
            0.0.1
         | 
| @@ -0,0 +1 @@ | |
| 1 | 
            +
            # Component dependencies
         | 
| @@ -0,0 +1,14 @@ | |
| 1 | 
            +
            # Place any code you want to run when the component is included on the client
         | 
| 2 | 
            +
            # or server.
         | 
| 3 | 
            +
             | 
| 4 | 
            +
            # To include code only on the client use:
         | 
| 5 | 
            +
            # if RUBY_PLATFORM == 'opal'
         | 
| 6 | 
            +
            #
         | 
| 7 | 
            +
            # To include code only on the server, use:
         | 
| 8 | 
            +
            # unless RUBY_PLATFORM == 'opal'
         | 
| 9 | 
            +
            # ^^ this will not send compile in code in the conditional to the client.
         | 
| 10 | 
            +
            # ^^ this include code required in the conditional.
         | 
| 11 | 
            +
            require 'mongo/lib/mongo_adaptor_client'
         | 
| 12 | 
            +
            if RUBY_PLATFORM != 'opal'
         | 
| 13 | 
            +
              require 'mongo/lib/mongo_adaptor_server'
         | 
| 14 | 
            +
            end
         | 
| @@ -0,0 +1 @@ | |
| 1 | 
            +
            # Component routes
         | 
| @@ -0,0 +1,74 @@ | |
| 1 | 
            +
            module Volt
         | 
| 2 | 
            +
              class DataStore
         | 
| 3 | 
            +
                class MongoAdaptorClient < BaseAdaptorClient
         | 
| 4 | 
            +
                  data_store_methods :find, :where, :skip, :order, :limit
         | 
| 5 | 
            +
             | 
| 6 | 
            +
                  module MongoArrayStore
         | 
| 7 | 
            +
                    # Find takes a query object
         | 
| 8 | 
            +
                    def where(query = {})
         | 
| 9 | 
            +
                      add_query_part(:find, query)
         | 
| 10 | 
            +
                    end
         | 
| 11 | 
            +
                    alias_method :find, :where
         | 
| 12 | 
            +
             | 
| 13 | 
            +
                    # .sort is already a ruby method, so we use order instead
         | 
| 14 | 
            +
                    def order(sort)
         | 
| 15 | 
            +
                      add_query_part(:sort, sort)
         | 
| 16 | 
            +
                    end
         | 
| 17 | 
            +
                  end
         | 
| 18 | 
            +
             | 
| 19 | 
            +
                  # Due to the way define_method works, we need to remove the generated
         | 
| 20 | 
            +
                  # methods from data_store_methods before we over-ride them.
         | 
| 21 | 
            +
                  Volt::Persistors::ArrayStore.send(:remove_method, :where)
         | 
| 22 | 
            +
                  Volt::Persistors::ArrayStore.send(:remove_method, :order)
         | 
| 23 | 
            +
             | 
| 24 | 
            +
                  # include mongo's methods on ArrayStore
         | 
| 25 | 
            +
                  Volt::Persistors::ArrayStore.include(MongoArrayStore)
         | 
| 26 | 
            +
             | 
| 27 | 
            +
                  def self.normalize_query(query)
         | 
| 28 | 
            +
                    query = merge_finds_and_move_to_front(query)
         | 
| 29 | 
            +
             | 
| 30 | 
            +
                    query = reject_skip_zero(query)
         | 
| 31 | 
            +
             | 
| 32 | 
            +
                    query
         | 
| 33 | 
            +
                  end
         | 
| 34 | 
            +
             | 
| 35 | 
            +
                  def self.merge_finds_and_move_to_front(query)
         | 
| 36 | 
            +
                    # Map first parts to string
         | 
| 37 | 
            +
                    query = query.map { |v| v[0] = v[0].to_s; v }
         | 
| 38 | 
            +
                    has_find = query.find { |v| v[0] == 'find' }
         | 
| 39 | 
            +
             | 
| 40 | 
            +
                    if has_find
         | 
| 41 | 
            +
                      # merge any finds
         | 
| 42 | 
            +
                      merged_find_query = {}
         | 
| 43 | 
            +
                      query = query.reject do |query_part|
         | 
| 44 | 
            +
                        if query_part[0] == 'find'
         | 
| 45 | 
            +
                          # on a find, merge into finds
         | 
| 46 | 
            +
                          find_query = query_part[1]
         | 
| 47 | 
            +
                          merged_find_query.merge!(find_query) if find_query
         | 
| 48 | 
            +
             | 
| 49 | 
            +
                          # reject
         | 
| 50 | 
            +
                          true
         | 
| 51 | 
            +
                        else
         | 
| 52 | 
            +
                          false
         | 
| 53 | 
            +
                        end
         | 
| 54 | 
            +
                      end
         | 
| 55 | 
            +
             | 
| 56 | 
            +
                      # Add finds to the front
         | 
| 57 | 
            +
                      query.insert(0, ['find', merged_find_query])
         | 
| 58 | 
            +
                    else
         | 
| 59 | 
            +
                      # No find was done, add it in the first position
         | 
| 60 | 
            +
                      query.insert(0, ['find'])
         | 
| 61 | 
            +
                    end
         | 
| 62 | 
            +
             | 
| 63 | 
            +
                    query
         | 
| 64 | 
            +
                  end
         | 
| 65 | 
            +
             | 
| 66 | 
            +
                  def self.reject_skip_zero(query)
         | 
| 67 | 
            +
                    query.reject do |query_part|
         | 
| 68 | 
            +
                      query_part[0] == 'skip' && query_part[1] == 0
         | 
| 69 | 
            +
                    end
         | 
| 70 | 
            +
                  end
         | 
| 71 | 
            +
             | 
| 72 | 
            +
                end
         | 
| 73 | 
            +
              end
         | 
| 74 | 
            +
            end
         | 
| @@ -0,0 +1,68 @@ | |
| 1 | 
            +
            require 'mongo'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            module Volt
         | 
| 4 | 
            +
              class DataStore
         | 
| 5 | 
            +
                class MongoAdaptorServer < BaseAdaptorServer
         | 
| 6 | 
            +
                  attr_reader :db, :mongo_db
         | 
| 7 | 
            +
             | 
| 8 | 
            +
                  def initialize
         | 
| 9 | 
            +
                    if Volt.config.db_uri.present?
         | 
| 10 | 
            +
                      @mongo_db ||= ::Mongo::MongoClient.from_uri(Volt.config.db_uri)
         | 
| 11 | 
            +
                      @db ||= @mongo_db.db(Volt.config.db_uri.split('/').last || Volt.config.db_name)
         | 
| 12 | 
            +
                    else
         | 
| 13 | 
            +
                      @mongo_db ||= ::Mongo::MongoClient.new(Volt.config.db_host, Volt.config.db_port)
         | 
| 14 | 
            +
                      @db ||= @mongo_db.db(Volt.config.db_name)
         | 
| 15 | 
            +
                    end
         | 
| 16 | 
            +
                  end
         | 
| 17 | 
            +
             | 
| 18 | 
            +
                  def insert(collection, values)
         | 
| 19 | 
            +
                    @db[collection].insert(values)
         | 
| 20 | 
            +
                  end
         | 
| 21 | 
            +
             | 
| 22 | 
            +
                  def update(collection, values)
         | 
| 23 | 
            +
                    # TODO: Seems mongo is dumb and doesn't let you upsert with custom id's
         | 
| 24 | 
            +
                    begin
         | 
| 25 | 
            +
                      @db[collection].insert(values)
         | 
| 26 | 
            +
                    rescue ::Mongo::OperationFailure => error
         | 
| 27 | 
            +
                      # Really mongo client?
         | 
| 28 | 
            +
                      if error.message[/^11000[:]/]
         | 
| 29 | 
            +
                        # Update because the id already exists
         | 
| 30 | 
            +
                        update_values = values.dup
         | 
| 31 | 
            +
                        id = update_values.delete(:_id)
         | 
| 32 | 
            +
                        @db[collection].update({ _id: id }, update_values)
         | 
| 33 | 
            +
                      else
         | 
| 34 | 
            +
                        return { error: error.message }
         | 
| 35 | 
            +
                      end
         | 
| 36 | 
            +
                    end
         | 
| 37 | 
            +
             | 
| 38 | 
            +
                    nil
         | 
| 39 | 
            +
                  end
         | 
| 40 | 
            +
             | 
| 41 | 
            +
                  def query(collection, query)
         | 
| 42 | 
            +
                    allowed_methods = %w(find skip limit)
         | 
| 43 | 
            +
             | 
| 44 | 
            +
                    cursor = @db[collection]
         | 
| 45 | 
            +
             | 
| 46 | 
            +
                    query.each do |query_part|
         | 
| 47 | 
            +
                      method_name, *args = query_part
         | 
| 48 | 
            +
             | 
| 49 | 
            +
                      unless allowed_methods.include?(method_name.to_s)
         | 
| 50 | 
            +
                        fail "`#{method_name}` is not part of a valid query"
         | 
| 51 | 
            +
                      end
         | 
| 52 | 
            +
             | 
| 53 | 
            +
                      cursor = cursor.send(method_name, *args)
         | 
| 54 | 
            +
                    end
         | 
| 55 | 
            +
             | 
| 56 | 
            +
                    cursor.to_a
         | 
| 57 | 
            +
                  end
         | 
| 58 | 
            +
             | 
| 59 | 
            +
                  def delete(collection, query)
         | 
| 60 | 
            +
                    @db[collection].remove(query)
         | 
| 61 | 
            +
                  end
         | 
| 62 | 
            +
             | 
| 63 | 
            +
                  def drop_database
         | 
| 64 | 
            +
                    db.connection.drop_database(Volt.config.db_name)
         | 
| 65 | 
            +
                  end
         | 
| 66 | 
            +
                end
         | 
| 67 | 
            +
              end
         | 
| 68 | 
            +
            end
         | 
    
        data/lib/volt/mongo.rb
    ADDED
    
    | @@ -0,0 +1,26 @@ | |
| 1 | 
            +
            # If you need to require in code in the gem's app folder, keep in mind that
         | 
| 2 | 
            +
            # the app is not on the load path when the gem is required.  Use
         | 
| 3 | 
            +
            # app/{gemname}/config/initializers/boot.rb to require in client or server
         | 
| 4 | 
            +
            # code.
         | 
| 5 | 
            +
            #
         | 
| 6 | 
            +
            # Also, in volt apps, you typically use the lib folder in the
         | 
| 7 | 
            +
            # app/{componentname} folder instead of this lib folder.  This lib folder is
         | 
| 8 | 
            +
            # for setting up gem code when Bundler.require is called. (or the gem is
         | 
| 9 | 
            +
            # required.)
         | 
| 10 | 
            +
            #
         | 
| 11 | 
            +
            # If you need to configure volt in some way, you can add a Volt.configure block
         | 
| 12 | 
            +
            # in this file.
         | 
| 13 | 
            +
             | 
| 14 | 
            +
            Volt.configure do |config|
         | 
| 15 | 
            +
              # Set the datastore to mongo
         | 
| 16 | 
            +
              config.public.datastore_name = 'mongo'
         | 
| 17 | 
            +
             | 
| 18 | 
            +
              # Include the mongo component on the client
         | 
| 19 | 
            +
              config.default_components << 'mongo'
         | 
| 20 | 
            +
            end
         | 
| 21 | 
            +
             | 
| 22 | 
            +
            module Volt
         | 
| 23 | 
            +
              module Mongo
         | 
| 24 | 
            +
                # Your code goes here...
         | 
| 25 | 
            +
              end
         | 
| 26 | 
            +
            end
         | 
    
        data/volt-mongo.gemspec
    ADDED
    
    | @@ -0,0 +1,26 @@ | |
| 1 | 
            +
            # coding: utf-8
         | 
| 2 | 
            +
            lib = File.expand_path('../lib', __FILE__)
         | 
| 3 | 
            +
            $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            version = File.read(File.expand_path('../VERSION', __FILE__)).strip
         | 
| 6 | 
            +
             | 
| 7 | 
            +
             | 
| 8 | 
            +
            Gem::Specification.new do |spec|
         | 
| 9 | 
            +
              spec.name          = "volt-mongo"
         | 
| 10 | 
            +
              spec.version       = version
         | 
| 11 | 
            +
              spec.authors       = ["Ryan Stout"]
         | 
| 12 | 
            +
              spec.email         = ["ryan@agileproductions.com"]
         | 
| 13 | 
            +
              spec.summary       = %q{Mongo database drivers for volt}
         | 
| 14 | 
            +
              spec.homepage      = ""
         | 
| 15 | 
            +
              spec.license       = "MIT"
         | 
| 16 | 
            +
             | 
| 17 | 
            +
              spec.files         = `git ls-files -z`.split("\x0")
         | 
| 18 | 
            +
              spec.executables   = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
         | 
| 19 | 
            +
              spec.test_files    = spec.files.grep(%r{^(test|spec|features)/})
         | 
| 20 | 
            +
              spec.require_paths = ["lib"]
         | 
| 21 | 
            +
             | 
| 22 | 
            +
              spec.add_dependency 'mongo', '~> 1.9.0'
         | 
| 23 | 
            +
             | 
| 24 | 
            +
              spec.add_development_dependency "volt", "~> 0.9.2"
         | 
| 25 | 
            +
              spec.add_development_dependency "rake"
         | 
| 26 | 
            +
            end
         | 
    
        metadata
    ADDED
    
    | @@ -0,0 +1,100 @@ | |
| 1 | 
            +
            --- !ruby/object:Gem::Specification
         | 
| 2 | 
            +
            name: volt-mongo
         | 
| 3 | 
            +
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            +
              version: 0.0.1
         | 
| 5 | 
            +
            platform: ruby
         | 
| 6 | 
            +
            authors:
         | 
| 7 | 
            +
            - Ryan Stout
         | 
| 8 | 
            +
            autorequire: 
         | 
| 9 | 
            +
            bindir: bin
         | 
| 10 | 
            +
            cert_chain: []
         | 
| 11 | 
            +
            date: 2015-05-13 00:00:00.000000000 Z
         | 
| 12 | 
            +
            dependencies:
         | 
| 13 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 14 | 
            +
              name: mongo
         | 
| 15 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 16 | 
            +
                requirements:
         | 
| 17 | 
            +
                - - "~>"
         | 
| 18 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 19 | 
            +
                    version: 1.9.0
         | 
| 20 | 
            +
              type: :runtime
         | 
| 21 | 
            +
              prerelease: false
         | 
| 22 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 23 | 
            +
                requirements:
         | 
| 24 | 
            +
                - - "~>"
         | 
| 25 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 26 | 
            +
                    version: 1.9.0
         | 
| 27 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 28 | 
            +
              name: volt
         | 
| 29 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 30 | 
            +
                requirements:
         | 
| 31 | 
            +
                - - "~>"
         | 
| 32 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 33 | 
            +
                    version: 0.9.2
         | 
| 34 | 
            +
              type: :development
         | 
| 35 | 
            +
              prerelease: false
         | 
| 36 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 37 | 
            +
                requirements:
         | 
| 38 | 
            +
                - - "~>"
         | 
| 39 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 40 | 
            +
                    version: 0.9.2
         | 
| 41 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 42 | 
            +
              name: rake
         | 
| 43 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 44 | 
            +
                requirements:
         | 
| 45 | 
            +
                - - ">="
         | 
| 46 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 47 | 
            +
                    version: '0'
         | 
| 48 | 
            +
              type: :development
         | 
| 49 | 
            +
              prerelease: false
         | 
| 50 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 51 | 
            +
                requirements:
         | 
| 52 | 
            +
                - - ">="
         | 
| 53 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 54 | 
            +
                    version: '0'
         | 
| 55 | 
            +
            description: 
         | 
| 56 | 
            +
            email:
         | 
| 57 | 
            +
            - ryan@agileproductions.com
         | 
| 58 | 
            +
            executables: []
         | 
| 59 | 
            +
            extensions: []
         | 
| 60 | 
            +
            extra_rdoc_files: []
         | 
| 61 | 
            +
            files:
         | 
| 62 | 
            +
            - ".gitignore"
         | 
| 63 | 
            +
            - Gemfile
         | 
| 64 | 
            +
            - README.md
         | 
| 65 | 
            +
            - Rakefile
         | 
| 66 | 
            +
            - VERSION
         | 
| 67 | 
            +
            - app/mongo/config/dependencies.rb
         | 
| 68 | 
            +
            - app/mongo/config/initializers/boot.rb
         | 
| 69 | 
            +
            - app/mongo/config/routes.rb
         | 
| 70 | 
            +
            - app/mongo/controllers/main_controller.rb
         | 
| 71 | 
            +
            - app/mongo/lib/mongo_adaptor_client.rb
         | 
| 72 | 
            +
            - app/mongo/lib/mongo_adaptor_server.rb
         | 
| 73 | 
            +
            - app/mongo/views/main/index.html
         | 
| 74 | 
            +
            - lib/volt/mongo.rb
         | 
| 75 | 
            +
            - volt-mongo.gemspec
         | 
| 76 | 
            +
            homepage: ''
         | 
| 77 | 
            +
            licenses:
         | 
| 78 | 
            +
            - MIT
         | 
| 79 | 
            +
            metadata: {}
         | 
| 80 | 
            +
            post_install_message: 
         | 
| 81 | 
            +
            rdoc_options: []
         | 
| 82 | 
            +
            require_paths:
         | 
| 83 | 
            +
            - lib
         | 
| 84 | 
            +
            required_ruby_version: !ruby/object:Gem::Requirement
         | 
| 85 | 
            +
              requirements:
         | 
| 86 | 
            +
              - - ">="
         | 
| 87 | 
            +
                - !ruby/object:Gem::Version
         | 
| 88 | 
            +
                  version: '0'
         | 
| 89 | 
            +
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 90 | 
            +
              requirements:
         | 
| 91 | 
            +
              - - ">="
         | 
| 92 | 
            +
                - !ruby/object:Gem::Version
         | 
| 93 | 
            +
                  version: '0'
         | 
| 94 | 
            +
            requirements: []
         | 
| 95 | 
            +
            rubyforge_project: 
         | 
| 96 | 
            +
            rubygems_version: 2.2.2
         | 
| 97 | 
            +
            signing_key: 
         | 
| 98 | 
            +
            specification_version: 4
         | 
| 99 | 
            +
            summary: Mongo database drivers for volt
         | 
| 100 | 
            +
            test_files: []
         |