muve-store-mongo 0.0.2

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 33464acefa3d59d3071f27af3019a285073dc7d1
4
+ data.tar.gz: a537c768adee7c8ca400d87607d0ad7ead7669ee
5
+ SHA512:
6
+ metadata.gz: fc049c900e092be9babe15d44e009424352f8bc6531a4dd419652f613334f45aa33082b4aeee3d1f11decf44b8da475c7f0fe9706cc47ad61a666db7bd404194
7
+ data.tar.gz: 7c769583d16f698a924313263fa2fba815cba80fb40a82a55e1e4dec893e9de0f271378fcc8c77d33fcc481a5df2504a3c1511abd8cc2934e828749315228dbb
data/.gitignore ADDED
@@ -0,0 +1,19 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ .rspec
19
+ .ruby-*
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ gem "bson_ext", "~> 1.10.2"
6
+
7
+ group :test do
8
+ gem "ffaker", "~> 1.24.0"
9
+ gem "factory_girl", "~> 4.0.0"
10
+ gem "rspec", "~> 3.0.0"
11
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 David Asabina
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,31 @@
1
+ # Muve::Store::Mongo
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/muve-store-mongo.svg)](http://badge.fury.io/rb/muve-store-mongo)
4
+ The muve-store-mongo gem is an implementation of the ```Muve::Store``` for use
5
+ with MongoDB datastores.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'muve-store-mongo'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install muve-store-mongo
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,15 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+ require "rake/testtask"
4
+ require "rdoc/task"
5
+
6
+ RSpec::Core::RakeTask.new('spec') do |t|
7
+ t.verbose = false
8
+ end
9
+
10
+ RDoc::Task.new do |rdoc|
11
+ rdoc.main = "README.rdoc"
12
+ rdoc.rdoc_files.include("lib/**/*.rb")
13
+ end
14
+
15
+ task default: :spec
@@ -0,0 +1,7 @@
1
+ module Muve
2
+ module Store
3
+ module Mongo
4
+ VERSION = "0.0.2"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,53 @@
1
+ require "muve-store-mongo/version"
2
+ require "muve"
3
+
4
+ module Muve
5
+ module Store
6
+ module Mongo
7
+ require 'mongo'
8
+
9
+ extend Muve::Store
10
+
11
+ def self.create(resource, details)
12
+ raise MuveInvalidAttributes, "invalid update data" unless details.kind_of? Hash
13
+ resource.database[resource.container].insert(details)
14
+ end
15
+
16
+ def self.fetch(resource, id, details={})
17
+ # TODO: discover a solution that works for situations where database
18
+ # driver returns string keys as well as symbol keys
19
+ details = {} unless details.kind_of? Hash
20
+ result = resource.database[resource.container].find_one(details.merge(_id: id))
21
+ result = Helper.symbolize_keys(result)
22
+ result[:id] = result.delete(:_id)
23
+ result
24
+ end
25
+
26
+ def self.find(resource, details)
27
+ details = {} unless details.kind_of? Hash
28
+ Enumerator.new do |result|
29
+ resource.database[resource.container].find(details).each do |item|
30
+ item = Helper.symbolize_keys(item)
31
+ item[:id] = item.delete(:_id)
32
+ result << item
33
+ end
34
+ end
35
+ end
36
+
37
+ def self.update(resource, id, details)
38
+ raise MuveInvalidAttributes, "invalid update data" unless details.kind_of? Hash
39
+ # TODO: raise error if details is not valid
40
+ resource.database[resource.container].find_and_modify(
41
+ query: { _id: id },
42
+ update: details
43
+ )
44
+ end
45
+
46
+ def self.delete(resource, id, details=nil)
47
+ details = {} unless details.kind_of? Hash
48
+ details = details.merge(_id: id) if id
49
+ resource.database[resource.container].remove(details)
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'muve-store-mongo/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "muve-store-mongo"
8
+ gem.version = Muve::Store::Mongo::VERSION
9
+ gem.authors = ["David Asabina"]
10
+ gem.email = ["david@supr.nu"]
11
+ gem.description = "The Mongo adaptor takes care of all the Mongo-related hassles while allowing you the trusty Muve interface"
12
+ gem.summary = "Mongo adaptor for the Muve engine"
13
+ gem.homepage = "https://github.com/vidbina/muve-store-mongo"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_runtime_dependency "muve", "~> 1.0.0"
21
+ gem.add_runtime_dependency "mongo", "~> 1.10.2"
22
+
23
+ gem.required_ruby_version = '>= 1.9.2'
24
+ end
@@ -0,0 +1,53 @@
1
+ require 'spec_helper'
2
+ require 'mongo'
3
+
4
+ describe 'Mongo Adaptor' do
5
+ let(:connection) { Mongo::MongoClient.new }
6
+ let(:database) { connection.db('muve_test') }
7
+ before do
8
+ class Place
9
+ include Muve::Model
10
+
11
+ def self.container
12
+ 'places'
13
+ end
14
+ end
15
+
16
+ Muve.init(connection, database)
17
+ end
18
+
19
+ it 'writes model data to the store' do
20
+ expect{
21
+ Muve::Store::Mongo.create(Place, {
22
+ city: Faker::Address.city,
23
+ street: Faker::Address.street_name,
24
+ building: Faker::Address.building_number
25
+ })
26
+ }.to change{database['places'].count}.by(1)
27
+ end
28
+
29
+ it 'writes modifications to the store' do
30
+ id = database['places'].insert(name: Faker::Venue.name)
31
+ new_name = Faker::Venue.name
32
+
33
+ expect{
34
+ Muve::Store::Mongo.update(Place, id, { name: new_name })
35
+ }.to change{database['places'].find_one(_id: id)['name']}.to(new_name)
36
+ end
37
+
38
+ it 'finds a resource from store' do
39
+ id = database['places'].insert(name: Faker::Venue.name)
40
+ expect(Muve::Store::Mongo.get(Place, id)[:id]).to eq(id)
41
+ end
42
+
43
+ it 'finds multiple resources from store' do
44
+ expect(Muve::Store::Mongo.find(Place, {})).to be_a(Enumerable)
45
+ end
46
+
47
+ it 'extracts a resource from every result in a multiple resource set' do
48
+ Muve::Store::Mongo.find(Place, {}).take(3).each do |result|
49
+ attributes = result.keys.map{ |i| i.to_s }
50
+ expect(attributes).to include('id', 'city', 'street', 'building')
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,91 @@
1
+ require 'bundler/setup'
2
+ Bundler.setup
3
+
4
+ require 'muve-store-mongo'
5
+
6
+ require 'ffaker'
7
+ require 'factory_girl'
8
+
9
+ # This file was generated by the `rspec --init` command. Conventionally, all
10
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
11
+ # The generated `.rspec` file contains `--require spec_helper` which will cause this
12
+ # file to always be loaded, without a need to explicitly require it in any files.
13
+ #
14
+ # Given that it is always loaded, you are encouraged to keep this file as
15
+ # light-weight as possible. Requiring heavyweight dependencies from this file
16
+ # will add to the boot time of your test suite on EVERY test run, even for an
17
+ # individual file that may not need all of that loaded. Instead, make a
18
+ # separate helper file that requires this one and then use it only in the specs
19
+ # that actually need it.
20
+ #
21
+ # The `.rspec` file also contains a few flags that are not defaults but that
22
+ # users commonly want.
23
+ #
24
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
25
+ RSpec.configure do |config|
26
+ config.include FactoryGirl::Syntax::Methods
27
+
28
+ config.before(:suite) do
29
+ #require 'factories.rb'
30
+ end
31
+ # The settings below are suggested to provide a good initial experience
32
+ # with RSpec, but feel free to customize to your heart's content.
33
+ =begin
34
+ # These two settings work together to allow you to limit a spec run
35
+ # to individual examples or groups you care about by tagging them with
36
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
37
+ # get run.
38
+ config.filter_run :focus
39
+ config.run_all_when_everything_filtered = true
40
+
41
+ # Many RSpec users commonly either run the entire suite or an individual
42
+ # file, and it's useful to allow more verbose output when running an
43
+ # individual spec file.
44
+ if config.files_to_run.one?
45
+ # Use the documentation formatter for detailed output,
46
+ # unless a formatter has already been configured
47
+ # (e.g. via a command-line flag).
48
+ config.default_formatter = 'doc'
49
+ end
50
+
51
+ # Print the 10 slowest examples and example groups at the
52
+ # end of the spec run, to help surface which specs are running
53
+ # particularly slow.
54
+ config.profile_examples = 10
55
+
56
+ # Run specs in random order to surface order dependencies. If you find an
57
+ # order dependency and want to debug it, you can fix the order by providing
58
+ # the seed, which is printed after each run.
59
+ # --seed 1234
60
+ config.order = :random
61
+
62
+ # Seed global randomization in this process using the `--seed` CLI option.
63
+ # Setting this allows you to use `--seed` to deterministically reproduce
64
+ # test failures related to randomization by passing the same `--seed` value
65
+ # as the one that triggered the failure.
66
+ Kernel.srand config.seed
67
+
68
+ # rspec-expectations config goes here. You can use an alternate
69
+ # assertion/expectation library such as wrong or the stdlib/minitest
70
+ # assertions if you prefer.
71
+ config.expect_with :rspec do |expectations|
72
+ # Enable only the newer, non-monkey-patching expect syntax.
73
+ # For more details, see:
74
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
75
+ expectations.syntax = :expect
76
+ end
77
+
78
+ # rspec-mocks config goes here. You can use an alternate test double
79
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
80
+ config.mock_with :rspec do |mocks|
81
+ # Enable only the newer, non-monkey-patching expect syntax.
82
+ # For more details, see:
83
+ # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
84
+ mocks.syntax = :expect
85
+
86
+ # Prevents you from mocking or stubbing a method that does not exist on
87
+ # a real object. This is generally recommended.
88
+ mocks.verify_partial_doubles = true
89
+ end
90
+ =end
91
+ end
metadata ADDED
@@ -0,0 +1,84 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: muve-store-mongo
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - David Asabina
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-07-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: muve
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 1.0.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.0.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: mongo
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 1.10.2
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 1.10.2
41
+ description: The Mongo adaptor takes care of all the Mongo-related hassles while allowing
42
+ you the trusty Muve interface
43
+ email:
44
+ - david@supr.nu
45
+ executables: []
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - ".gitignore"
50
+ - Gemfile
51
+ - LICENSE.txt
52
+ - README.md
53
+ - Rakefile
54
+ - lib/muve-store-mongo.rb
55
+ - lib/muve-store-mongo/version.rb
56
+ - muve-store-mongo.gemspec
57
+ - spec/mongo_spec.rb
58
+ - spec/spec_helper.rb
59
+ homepage: https://github.com/vidbina/muve-store-mongo
60
+ licenses: []
61
+ metadata: {}
62
+ post_install_message:
63
+ rdoc_options: []
64
+ require_paths:
65
+ - lib
66
+ required_ruby_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: 1.9.2
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ requirements: []
77
+ rubyforge_project:
78
+ rubygems_version: 2.2.2
79
+ signing_key:
80
+ specification_version: 4
81
+ summary: Mongo adaptor for the Muve engine
82
+ test_files:
83
+ - spec/mongo_spec.rb
84
+ - spec/spec_helper.rb