mordor 0.2.20 → 0.3.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.circleci/config.yml +79 -0
- data/.gitignore +2 -0
- data/CHANGES.md +9 -0
- data/Gemfile +2 -16
- data/Guardfile +39 -0
- data/README.md +1 -1
- data/Rakefile +8 -1
- data/ext/mkrf_conf.rb +21 -0
- data/lib/mordor/config.rb +11 -2
- data/lib/mordor/resource.rb +70 -9
- data/lib/mordor/version.rb +1 -1
- data/mordor.gemspec +26 -18
- data/spec/mordor/collection_spec.rb +3 -3
- data/spec/mordor/connection_spec.rb +77 -30
- data/spec/mordor/resource_spec.rb +3 -3
- data/spec/spec_helper.rb +1 -9
- data/tasks/github-gem.rake +18 -10
- metadata +151 -150
- data/.travis.yml +0 -21
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 180551390281de15f455fca31a7d989da1347024f79b207032e27bbc05cfef62
|
4
|
+
data.tar.gz: 68939c6cbff96d3f00ad86eb0763fb236239df59e34a2c6d88cc2465598184dd
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: dbed0a87024d1ae6c3a3fac6eb7275882dd1810be8d52b5e15ba53ef29fc4957a90289bc324688ae89e877e29c1c977685d08febef55bd997f560bb1f611d7af
|
7
|
+
data.tar.gz: 75672c34cce2e9e02053459632832495a972d6f2fc706d1daf3522a29a9191b2c7b624f1d8d30fc1f1e5f661570c038ed8f4349240eb4abb7531efe636344d47
|
@@ -0,0 +1,79 @@
|
|
1
|
+
# Ruby CircleCI 2.0 configuration file
|
2
|
+
#
|
3
|
+
# Check https://circleci.com/docs/2.0/language-ruby/ for more details
|
4
|
+
#
|
5
|
+
version: 2
|
6
|
+
jobs:
|
7
|
+
build:
|
8
|
+
docker:
|
9
|
+
# specify the version you desire here
|
10
|
+
- image: circleci/ruby:2.6.5
|
11
|
+
- image: mongo:3.2
|
12
|
+
|
13
|
+
working_directory: ~/repo
|
14
|
+
|
15
|
+
steps:
|
16
|
+
- checkout
|
17
|
+
|
18
|
+
- run:
|
19
|
+
name: install dependencies
|
20
|
+
command: |
|
21
|
+
bundle install --jobs=4 --retry=3 --path vendor/bundle
|
22
|
+
|
23
|
+
# run tests!
|
24
|
+
- run:
|
25
|
+
name: run tests
|
26
|
+
command: |
|
27
|
+
mkdir /tmp/test-results
|
28
|
+
TEST_FILES="$(circleci tests glob "spec/**/*_spec.rb" | \
|
29
|
+
circleci tests split --split-by=timings)"
|
30
|
+
bundle exec rspec \
|
31
|
+
--format progress \
|
32
|
+
--format RspecJunitFormatter \
|
33
|
+
--out /tmp/test-results/rspec.xml \
|
34
|
+
--format progress \
|
35
|
+
$TEST_FILES
|
36
|
+
# collect reports
|
37
|
+
- store_test_results:
|
38
|
+
path: /tmp/test-results
|
39
|
+
- store_artifacts:
|
40
|
+
path: /tmp/test-results
|
41
|
+
destination: test-results
|
42
|
+
|
43
|
+
environment:
|
44
|
+
TZ: CET
|
45
|
+
|
46
|
+
rubygems_release:
|
47
|
+
docker:
|
48
|
+
- image: circleci/ruby:2.6.5
|
49
|
+
|
50
|
+
working_directory: ~/repo
|
51
|
+
|
52
|
+
steps:
|
53
|
+
- checkout
|
54
|
+
|
55
|
+
- run:
|
56
|
+
name: install dependencies
|
57
|
+
command: |
|
58
|
+
bundle install --jobs=4 --retry=3 --path vendor/bundle
|
59
|
+
|
60
|
+
- run:
|
61
|
+
name: release to RubyGems
|
62
|
+
command: |
|
63
|
+
bundle exec rake gem:release
|
64
|
+
|
65
|
+
workflows:
|
66
|
+
version: 2
|
67
|
+
CircleCI:
|
68
|
+
jobs:
|
69
|
+
- build:
|
70
|
+
filters:
|
71
|
+
branches:
|
72
|
+
only: /.*/
|
73
|
+
|
74
|
+
- ruby_gems:
|
75
|
+
filters:
|
76
|
+
branches:
|
77
|
+
only: master
|
78
|
+
|
79
|
+
|
data/.gitignore
CHANGED
data/CHANGES.md
ADDED
data/Gemfile
CHANGED
@@ -1,17 +1,3 @@
|
|
1
|
-
source "
|
2
|
-
# Add dependencies required to use your gem here.
|
3
|
-
# Example:
|
4
|
-
# gem "activesupport", ">= 2.3.5"
|
1
|
+
source "https://rubygems.org"
|
5
2
|
|
6
|
-
|
7
|
-
# Include everything needed to run rake, tests, features, etc.
|
8
|
-
gem "rake"
|
9
|
-
gem "extlib"
|
10
|
-
gem "mongo"
|
11
|
-
gem "bson_ext", :platforms => :ruby
|
12
|
-
gem "json"
|
13
|
-
|
14
|
-
group :test do
|
15
|
-
gem "rspec", "~> 2.0"
|
16
|
-
gem "rack-test"
|
17
|
-
end
|
3
|
+
gemspec
|
data/Guardfile
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# A sample Guardfile
|
2
|
+
# More info at https://github.com/guard/guard#readme
|
3
|
+
|
4
|
+
## Uncomment and set this to only include directories you want to watch
|
5
|
+
# directories %w(app lib config test spec features)
|
6
|
+
|
7
|
+
## Uncomment to clear the screen before every task
|
8
|
+
# clearing :on
|
9
|
+
|
10
|
+
## Guard internally checks for changes in the Guardfile and exits.
|
11
|
+
## If you want Guard to automatically start up again, run guard in a
|
12
|
+
## shell loop, e.g.:
|
13
|
+
##
|
14
|
+
## $ while bundle exec guard; do echo "Restarting Guard..."; done
|
15
|
+
##
|
16
|
+
## Note: if you are using the `directories` clause above and you are not
|
17
|
+
## watching the project directory ('.'), then you will want to move
|
18
|
+
## the Guardfile to a watched dir and symlink it back, e.g.
|
19
|
+
#
|
20
|
+
# $ mkdir config
|
21
|
+
# $ mv Guardfile config/
|
22
|
+
# $ ln -s config/Guardfile .
|
23
|
+
#
|
24
|
+
# and, you'll have to watch "config/Guardfile" instead of "Guardfile"
|
25
|
+
|
26
|
+
# Note: The cmd option is now required due to the increasing number of ways
|
27
|
+
# rspec may be run, below are examples of the most common uses.
|
28
|
+
# * bundler: 'bundle exec rspec'
|
29
|
+
# * bundler binstubs: 'bin/rspec'
|
30
|
+
# * spring: 'bin/rsspec' (This will use spring if running and you have
|
31
|
+
# installed the spring binstubs per the docs)
|
32
|
+
# * zeus: 'zeus rspec' (requires the server to be started separetly)
|
33
|
+
# * 'just' rspec: 'rspec'
|
34
|
+
|
35
|
+
guard :rspec, cmd: 'bundle exec rspec' do
|
36
|
+
watch(%r{^spec/.+_spec\.rb$})
|
37
|
+
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
|
38
|
+
watch('spec/spec_helper.rb') { "spec" }
|
39
|
+
end
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
[![
|
1
|
+
[![CircleCI](https://circleci.com/gh/nedap/mordor/tree/master.svg?style=svg)](https://circleci.com/gh/nedap/mordor/tree/master)
|
2
2
|
|
3
3
|
## Introduction
|
4
4
|
Small library to add DataMapper style resources for MongoDB.
|
data/Rakefile
CHANGED
@@ -3,7 +3,14 @@ require "bundler"
|
|
3
3
|
|
4
4
|
Bundler.setup
|
5
5
|
|
6
|
-
|
6
|
+
module TempFixForRakeLastComment
|
7
|
+
def last_comment
|
8
|
+
last_description
|
9
|
+
end
|
10
|
+
end
|
11
|
+
Rake::Application.send :include, TempFixForRakeLastComment
|
12
|
+
|
13
|
+
load('./tasks/github-gem.rake')
|
7
14
|
|
8
15
|
task :default => :spec
|
9
16
|
|
data/ext/mkrf_conf.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'rubygems/dependency_installer'
|
2
|
+
|
3
|
+
gdi = Gem::DependencyInstaller.new
|
4
|
+
|
5
|
+
begin
|
6
|
+
if RUBY_PLATFORM == 'java'
|
7
|
+
puts "Not installing bson_ext gem, because we're running on JRuby"
|
8
|
+
else
|
9
|
+
puts "Installing bson_ext"
|
10
|
+
gdi.install "bson_ext"
|
11
|
+
end
|
12
|
+
rescue => e
|
13
|
+
warn "#{$0}: #{e}"
|
14
|
+
|
15
|
+
exit!
|
16
|
+
end
|
17
|
+
|
18
|
+
# Write fake Rakefile for rake since Makefile isn't used
|
19
|
+
File.open(File.join(File.dirname(__FILE__), 'Rakefile'), 'w') do |f|
|
20
|
+
f.write("task :default" + $/)
|
21
|
+
end
|
data/lib/mordor/config.rb
CHANGED
@@ -18,11 +18,17 @@ module Mordor
|
|
18
18
|
#
|
19
19
|
# :api: publicdef use
|
20
20
|
def use
|
21
|
-
@configuration ||=
|
21
|
+
@configuration ||= defaults
|
22
22
|
yield @configuration
|
23
23
|
nil
|
24
24
|
end
|
25
25
|
|
26
|
+
# Resets the configuration to its default state
|
27
|
+
#
|
28
|
+
def reset
|
29
|
+
setup
|
30
|
+
end
|
31
|
+
|
26
32
|
# Retrieve the value of a config entry.
|
27
33
|
#
|
28
34
|
# ==== Parameters
|
@@ -59,7 +65,10 @@ module Mordor
|
|
59
65
|
@defaults ||= {
|
60
66
|
:hostname => 'localhost',
|
61
67
|
:port => 27017,
|
62
|
-
:database => 'development'
|
68
|
+
:database => 'development',
|
69
|
+
:pool_size => nil,
|
70
|
+
:pool_timeout => nil,
|
71
|
+
:rs_refresh_mode => :sync,
|
63
72
|
}
|
64
73
|
end
|
65
74
|
|
data/lib/mordor/resource.rb
CHANGED
@@ -172,15 +172,12 @@ module Mordor
|
|
172
172
|
|
173
173
|
def database
|
174
174
|
unless @db
|
175
|
-
if
|
176
|
-
|
177
|
-
options[:rs_name] = Mordor::Config[:replica_set] if Mordor::Config[:replica_set]
|
178
|
-
connection = Mongo::MongoReplicaSetClient.new(hosts, options)
|
175
|
+
if connecting_to_replica_set?
|
176
|
+
client = new_replica_set_client
|
179
177
|
else
|
180
|
-
|
178
|
+
client = new_mongo_connection
|
181
179
|
end
|
182
|
-
@db =
|
183
|
-
@db.authenticate(Mordor::Config[:username], Mordor::Config[:password]) if Mordor::Config[:username]
|
180
|
+
@db = database_connection(client)
|
184
181
|
end
|
185
182
|
|
186
183
|
@db
|
@@ -238,7 +235,6 @@ module Mordor
|
|
238
235
|
if options[:index]
|
239
236
|
@indices << name unless @indices.include?(name)
|
240
237
|
@index_types[name] = options[:index_type] ? options[:index_type] : Mongo::DESCENDING
|
241
|
-
ensure_index(name)
|
242
238
|
end
|
243
239
|
|
244
240
|
if options[:timestamp]
|
@@ -265,7 +261,8 @@ module Mordor
|
|
265
261
|
EOS
|
266
262
|
end
|
267
263
|
|
268
|
-
|
264
|
+
private
|
265
|
+
|
269
266
|
def perform_collection_find(query, options = {})
|
270
267
|
ensure_indices
|
271
268
|
collection.find(query, options)
|
@@ -318,6 +315,70 @@ module Mordor
|
|
318
315
|
def day_to_query(day)
|
319
316
|
date_range_to_query( day_to_range(day) )
|
320
317
|
end
|
318
|
+
|
319
|
+
# Connection setup
|
320
|
+
|
321
|
+
def new_mongo_connection
|
322
|
+
Mongo::Connection.new(*mongo_connection_args)
|
323
|
+
end
|
324
|
+
|
325
|
+
def new_replica_set_client
|
326
|
+
Mongo::MongoReplicaSetClient.new(*replica_set_client_args)
|
327
|
+
end
|
328
|
+
|
329
|
+
def database_connection(client)
|
330
|
+
client.db(Mordor::Config[:database]).tap do |db|
|
331
|
+
db.authenticate(*authentication_args) if authentication_args.any?
|
332
|
+
end
|
333
|
+
end
|
334
|
+
|
335
|
+
# Connection arguments
|
336
|
+
|
337
|
+
def mongo_connection_args
|
338
|
+
args = [ Mordor::Config[:hostname], Mordor::Config[:port] ]
|
339
|
+
args << connection_pool_options if connection_pool_options.any?
|
340
|
+
args
|
341
|
+
end
|
342
|
+
|
343
|
+
def replica_set_client_args
|
344
|
+
[ replica_set_host_list, replica_set_options ]
|
345
|
+
end
|
346
|
+
|
347
|
+
def authentication_args
|
348
|
+
args = []
|
349
|
+
if user_name = Mordor::Config[:username]
|
350
|
+
args << user_name
|
351
|
+
args << Mordor::Config[:password] if Mordor::Config[:password]
|
352
|
+
end
|
353
|
+
args
|
354
|
+
end
|
355
|
+
|
356
|
+
# Connection options
|
357
|
+
|
358
|
+
def connection_pool_options
|
359
|
+
@connection_pool_options ||= Hash.new.tap do |hash|
|
360
|
+
hash[:pool_size] = Mordor::Config[:pool_size] if Mordor::Config[:pool_size]
|
361
|
+
hash[:pool_timeout] = Mordor::Config[:pool_timeout] if Mordor::Config[:pool_timeout]
|
362
|
+
end
|
363
|
+
end
|
364
|
+
|
365
|
+
def replica_set_options
|
366
|
+
@replica_set_options ||= connection_pool_options.tap do |hash|
|
367
|
+
hash[:refresh_mode] = Mordor::Config[:rs_refresh_mode]
|
368
|
+
hash[:rs_name] = Mordor::Config[:replica_set] if Mordor::Config[:replica_set]
|
369
|
+
end
|
370
|
+
end
|
371
|
+
|
372
|
+
# Replica set helpers
|
373
|
+
|
374
|
+
def replica_set_host_list
|
375
|
+
@replica_set_hosts ||= Mordor::Config[:hostname].split(',').map(&:strip).compact
|
376
|
+
end
|
377
|
+
|
378
|
+
def connecting_to_replica_set?
|
379
|
+
replica_set_host_list.size > 1
|
380
|
+
end
|
381
|
+
|
321
382
|
end
|
322
383
|
end
|
323
384
|
end
|
data/lib/mordor/version.rb
CHANGED
data/mordor.gemspec
CHANGED
@@ -1,32 +1,40 @@
|
|
1
|
+
require './lib/mordor/version'
|
2
|
+
|
1
3
|
Gem::Specification.new do |s|
|
2
|
-
s.name =
|
3
|
-
|
4
|
+
s.name = 'mordor'
|
5
|
+
|
4
6
|
# Do not set the version and date field manually, this is done by the release script
|
5
|
-
s.version = "0.
|
6
|
-
s.date = "
|
7
|
+
s.version = "0.3.5"
|
8
|
+
s.date = "2020-07-28"
|
7
9
|
|
8
|
-
s.summary =
|
10
|
+
s.summary = 'mordor'
|
9
11
|
s.description = <<-eos
|
10
12
|
Small gem to add MongoDB Resources, resources have attributes that translate into document fields. When an attribute is declared, finders for the attribute are added to the Resource automatically
|
11
13
|
eos
|
12
14
|
|
13
|
-
s.
|
14
|
-
s.
|
15
|
-
s.
|
15
|
+
s.authors = ['Jan-Willem Koelewijn', 'Dirkjan Bussink']
|
16
|
+
s.email = ['janwillem.koelewijn@nedap.com', 'dirkjan.bussink@nedap.com']
|
17
|
+
s.homepage = 'http://github.com/jwkoelewijn/mordor/'
|
18
|
+
|
19
|
+
s.add_runtime_dependency 'extlib'
|
20
|
+
s.add_runtime_dependency 'json', '~> 2.3.0'
|
21
|
+
s.add_runtime_dependency 'mongo', '< 2.0.0'
|
16
22
|
|
17
|
-
s.add_development_dependency
|
18
|
-
s.add_development_dependency
|
23
|
+
s.add_development_dependency 'rack-test'
|
24
|
+
s.add_development_dependency 'guard-rspec'
|
25
|
+
s.add_development_dependency 'rake', '~> 12.3.3'
|
26
|
+
s.add_development_dependency 'rspec', '~> 2.0', '< 2.99'
|
27
|
+
s.add_development_dependency 'rspec_junit_formatter'
|
19
28
|
|
20
|
-
s.
|
21
|
-
s.add_runtime_dependency('mongo')
|
22
|
-
s.add_runtime_dependency('json')
|
29
|
+
s.extensions << 'ext/mkrf_conf.rb'
|
23
30
|
|
24
|
-
|
25
|
-
|
26
|
-
|
31
|
+
if defined? JRUBY_VERSION
|
32
|
+
s.platform = 'java'
|
33
|
+
else
|
34
|
+
s.add_runtime_dependency('bson_ext')
|
35
|
+
end
|
27
36
|
|
28
37
|
# The files and test_files directives are set automatically by the release script.
|
29
38
|
# Do not change them by hand, but make sure to add the files to the git repository.
|
30
|
-
s.files = %w(.gitignore .
|
39
|
+
s.files = %w(.circleci/config.yml .gitignore CHANGES.md Gemfile Guardfile LICENSE README.md Rakefile ext/mkrf_conf.rb lib/mordor.rb lib/mordor/collection.rb lib/mordor/config.rb lib/mordor/resource.rb lib/mordor/version.rb mordor.gemspec spec/mordor/collection_spec.rb spec/mordor/connection_spec.rb spec/mordor/resource_spec.rb spec/spec.opts spec/spec_helper.rb tasks/github-gem.rake)
|
31
40
|
end
|
32
|
-
|
@@ -19,7 +19,7 @@ describe "with respect to collections" do
|
|
19
19
|
before :each do
|
20
20
|
5.times do |index|
|
21
21
|
res = TestResource.new(:first => "#{index}_first", :second => "#{index}_second", :third => "#{index}_third")
|
22
|
-
res.save.should
|
22
|
+
res.save.should be true
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
@@ -40,7 +40,7 @@ describe "with respect to collections" do
|
|
40
40
|
before :each do
|
41
41
|
5.times do |index|
|
42
42
|
res = TestResource.new(:first => "#{index}_first", :second => "#{index}_second", :third => "#{index}_third")
|
43
|
-
res.save.should
|
43
|
+
res.save.should be true
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
@@ -78,7 +78,7 @@ describe "with respect to collections" do
|
|
78
78
|
before :each do
|
79
79
|
5.times do |index|
|
80
80
|
res = TestResource.new(:first => "#{index}_first", :second => "#{index}_second", :third => "#{index}_third")
|
81
|
-
res.save.should
|
81
|
+
res.save.should be true
|
82
82
|
end
|
83
83
|
end
|
84
84
|
|
@@ -7,15 +7,17 @@ describe "connecting to mongo" do
|
|
7
7
|
end
|
8
8
|
end
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
10
|
+
describe 'database connection' do
|
11
|
+
it "should have a mongo database " do
|
12
|
+
TestResource.database.should be_instance_of(Mongo::DB)
|
13
|
+
end
|
13
14
|
|
14
|
-
|
15
|
-
|
16
|
-
|
15
|
+
it "should select the correct database" do
|
16
|
+
database_name = "any_database_name"
|
17
|
+
Mordor::Config.use { |config| config[:database] = database_name }
|
17
18
|
|
18
|
-
|
19
|
+
TestResource.database.name.should == database_name
|
20
|
+
end
|
19
21
|
end
|
20
22
|
|
21
23
|
describe "when credentials are provided" do
|
@@ -27,8 +29,8 @@ describe "connecting to mongo" do
|
|
27
29
|
config[:password] = credentials[:password]
|
28
30
|
end
|
29
31
|
|
30
|
-
@mock_db =
|
31
|
-
Mongo::Connection.stub(:new).and_return(
|
32
|
+
@mock_db = double("db")
|
33
|
+
Mongo::Connection.stub(:new).and_return(double("connection", :db => @mock_db))
|
32
34
|
end
|
33
35
|
|
34
36
|
it "should authenticate with username and password" do
|
@@ -39,58 +41,103 @@ describe "connecting to mongo" do
|
|
39
41
|
|
40
42
|
describe "the Mongo database connection" do
|
41
43
|
before :each do
|
42
|
-
@mock_connection =
|
44
|
+
@mock_connection = double("connection", :db => double("db"))
|
45
|
+
end
|
46
|
+
|
47
|
+
after :each do
|
48
|
+
TestResource.database
|
43
49
|
end
|
44
50
|
|
45
51
|
it "should connect with specified host" do
|
46
52
|
host = "any host IP or reachable hostname"
|
47
53
|
Mordor::Config.use { |config| config[:hostname] = host }
|
48
|
-
|
49
54
|
Mongo::Connection.should_receive(:new).with(host, anything).and_return(@mock_connection)
|
50
|
-
|
51
|
-
TestResource.database
|
52
55
|
end
|
53
56
|
|
54
57
|
it "should connect on specified port" do
|
55
58
|
port = rand(10000)
|
56
59
|
Mordor::Config.use { |config| config[:port] = port }
|
57
|
-
|
58
60
|
Mongo::Connection.should_receive(:new).with(anything, port).and_return(@mock_connection)
|
61
|
+
end
|
59
62
|
|
60
|
-
|
63
|
+
describe 'setting connection pool options' do
|
64
|
+
it 'supports setting pool size' do
|
65
|
+
Mordor::Config.use { |config| config[:pool_size] = 7 }
|
66
|
+
Mongo::Connection.should_receive(:new).with('localhost', 27017, pool_size: 7).and_return(@mock_connection)
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'supports setting pool timeout' do
|
70
|
+
Mordor::Config.use { |config| config[:pool_timeout] = 8 }
|
71
|
+
Mongo::Connection.should_receive(:new).with('localhost', 27017, pool_timeout: 8).and_return(@mock_connection)
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'supports setting both' do
|
75
|
+
Mordor::Config.use { |config|
|
76
|
+
config[:pool_size] = 9
|
77
|
+
config[:pool_timeout] = 10
|
78
|
+
}
|
79
|
+
Mongo::Connection.should_receive(:new).with('localhost', 27017, pool_size: 9, pool_timeout: 10).and_return(@mock_connection)
|
80
|
+
end
|
61
81
|
end
|
62
82
|
end
|
63
83
|
|
64
84
|
describe "replica sets" do
|
65
85
|
before :each do
|
66
|
-
@mock_connection =
|
86
|
+
@mock_connection = double("connection", :db => double("db"))
|
87
|
+
Mordor::Config.use { |config| config[:hostname] = host_string }
|
67
88
|
end
|
68
89
|
|
69
|
-
|
70
|
-
|
71
|
-
|
90
|
+
after :each do
|
91
|
+
TestResource.database
|
92
|
+
end
|
72
93
|
|
73
|
-
|
94
|
+
let(:host_string){ 'localhost:27017, localhost:27018 ' }
|
95
|
+
let(:hosts_array){ host_string.split(',').map(&:strip) }
|
96
|
+
let(:replica_set_string){ 'sample replica set' }
|
74
97
|
|
98
|
+
it "creates a mongo replica set client when multiple hosts are provided" do
|
75
99
|
Mongo::MongoReplicaSetClient.should_receive(:new).with(hosts_array, anything).and_return(@mock_connection)
|
76
|
-
|
77
|
-
TestResource.database
|
78
100
|
end
|
79
101
|
|
80
102
|
it "creates a mongo replica set client with the correct replica set name if given" do
|
81
|
-
hosts = "localhost:27017, localhost:27018 "
|
82
|
-
replica_set = "sample replica set"
|
83
|
-
|
84
103
|
Mordor::Config.use do |config|
|
85
|
-
config[:
|
86
|
-
config[:replica_set] = replica_set
|
104
|
+
config[:replica_set] = replica_set_string
|
87
105
|
end
|
88
|
-
|
89
|
-
options = {:rs_name => replica_set, :refresh_mode => :sync}
|
106
|
+
options = {:rs_name => replica_set_string, :refresh_mode => :sync}
|
90
107
|
|
91
108
|
Mongo::MongoReplicaSetClient.should_receive(:new).with(anything, options).and_return(@mock_connection)
|
109
|
+
end
|
92
110
|
|
93
|
-
|
111
|
+
describe 'setting connection pool options' do
|
112
|
+
it 'supports setting pool size' do
|
113
|
+
Mordor::Config.use do |config|
|
114
|
+
config[:pool_size] = 1
|
115
|
+
end
|
116
|
+
options = {:pool_size => 1, :refresh_mode => :sync}
|
117
|
+
|
118
|
+
Mongo::MongoReplicaSetClient.should_receive(:new).with(anything, options).and_return(@mock_connection)
|
119
|
+
end
|
120
|
+
|
121
|
+
it 'supports setting pool timeout' do
|
122
|
+
Mordor::Config.use do |config|
|
123
|
+
config[:pool_timeout] = 1
|
124
|
+
end
|
125
|
+
|
126
|
+
options = {:pool_timeout => 1, :refresh_mode => :sync}
|
127
|
+
Mongo::MongoReplicaSetClient.should_receive(:new).with(anything, options).and_return(@mock_connection)
|
128
|
+
end
|
129
|
+
|
130
|
+
it 'supports setting both' do
|
131
|
+
Mordor::Config.use do |config|
|
132
|
+
config[:pool_size] = 5
|
133
|
+
config[:pool_timeout] = 1
|
134
|
+
config[:replica_set] = replica_set_string
|
135
|
+
end
|
136
|
+
options = {:pool_size => 5, :pool_timeout => 1, :refresh_mode => :sync, :rs_name => replica_set_string}
|
137
|
+
|
138
|
+
Mongo::MongoReplicaSetClient.should_receive(:new).with(anything, options).and_return(@mock_connection)
|
139
|
+
end
|
94
140
|
end
|
141
|
+
|
95
142
|
end
|
96
143
|
end
|
@@ -95,7 +95,7 @@ describe "with respect to resources" do
|
|
95
95
|
|
96
96
|
it "should correctly replace BigDecimals" do
|
97
97
|
options = {
|
98
|
-
"option" => BigDecimal
|
98
|
+
"option" => BigDecimal("1.00")
|
99
99
|
}
|
100
100
|
result = TestResource.new.replace_params(options)
|
101
101
|
result.each do |k,v|
|
@@ -249,12 +249,12 @@ describe "with respect to resources" do
|
|
249
249
|
TestResource.ensure_count.should == 2 # For each index
|
250
250
|
end
|
251
251
|
|
252
|
-
it "should call ensure index for each index attribute on
|
252
|
+
it "should not call ensure index for each index attribute on file eval" do
|
253
253
|
TestResource2.class_eval do
|
254
254
|
attribute :test_attribute, :index => true
|
255
255
|
end
|
256
256
|
|
257
|
-
TestResource2.ensure_count.should ==
|
257
|
+
TestResource2.ensure_count.should == 0
|
258
258
|
end
|
259
259
|
end
|
260
260
|
|
data/spec/spec_helper.rb
CHANGED
@@ -15,13 +15,7 @@ RSpec.configure do |config|
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def reset_mordor_config
|
18
|
-
Mordor::Config.
|
19
|
-
config[:username] = nil
|
20
|
-
config[:password] = nil
|
21
|
-
config[:hostname] = '127.0.0.1'
|
22
|
-
config[:port] = 27017
|
23
|
-
config[:database] = 'test'
|
24
|
-
end
|
18
|
+
Mordor::Config.reset
|
25
19
|
end
|
26
20
|
|
27
21
|
def drop_db_collections
|
@@ -45,5 +39,3 @@ end
|
|
45
39
|
def test_class_names
|
46
40
|
[:TestResource, :TestResource2, :TestTimedResource]
|
47
41
|
end
|
48
|
-
|
49
|
-
|
data/tasks/github-gem.rake
CHANGED
@@ -135,7 +135,7 @@ module GithubGem
|
|
135
135
|
|
136
136
|
desc "Release a new version of the gem using the VERSION environment variable"
|
137
137
|
task(:release => release_tasks) { release_task }
|
138
|
-
|
138
|
+
|
139
139
|
namespace(:release) do
|
140
140
|
desc "Release the next version of the gem, by incrementing the last version segment by 1"
|
141
141
|
task(:next => [:next_version] + release_tasks) { release_task }
|
@@ -161,7 +161,7 @@ module GithubGem
|
|
161
161
|
task(:next_patch_version) { next_version_task(:patch) }
|
162
162
|
task(:next_minor_version) { next_version_task(:minor) }
|
163
163
|
task(:next_major_version) { next_version_task(:major) }
|
164
|
-
|
164
|
+
|
165
165
|
desc "Updates the gem release tasks with the latest version on Github"
|
166
166
|
task(:update_tasks) { update_tasks_task }
|
167
167
|
end
|
@@ -182,11 +182,11 @@ module GithubGem
|
|
182
182
|
def build_task
|
183
183
|
sh "gem build -q #{gemspec_file}"
|
184
184
|
Dir.mkdir('pkg') unless File.exist?('pkg')
|
185
|
-
sh "mv #{
|
185
|
+
sh "mv #{gem_package_filename}.gem pkg/#{gem_package_filename}.gem"
|
186
186
|
end
|
187
187
|
|
188
188
|
def newest_version
|
189
|
-
`#{git} tag`.split("\n").map { |tag| tag.split('-').last }.compact.map { |v| Gem::Version.new(v) }.max || Gem::Version.new('0.0.0')
|
189
|
+
`#{git} tag`.split("\n").map { |tag| tag.split('mordor-').last }.compact.map { |v| Gem::Version.new(v) }.max || Gem::Version.new('0.0.0')
|
190
190
|
end
|
191
191
|
|
192
192
|
def next_version(increment = nil)
|
@@ -198,11 +198,11 @@ module GithubGem
|
|
198
198
|
when :major then 0
|
199
199
|
else next_version.length - 1
|
200
200
|
end
|
201
|
-
|
201
|
+
|
202
202
|
next_version[increment_index] ||= 0
|
203
203
|
next_version[increment_index] = next_version[increment_index].succ
|
204
204
|
((increment_index + 1)...next_version.length).each { |i| next_version[i] = 0 }
|
205
|
-
|
205
|
+
|
206
206
|
Gem::Version.new(next_version.join('.'))
|
207
207
|
end
|
208
208
|
|
@@ -258,7 +258,7 @@ module GithubGem
|
|
258
258
|
|
259
259
|
# Adds a tag for the released version
|
260
260
|
def tag_version_task
|
261
|
-
sh git, 'tag', '-a', "#{gemspec.
|
261
|
+
sh git, 'tag', '-a', "v#{gemspec.version}", '-m', "Released #{gemspec.name} gem version #{gemspec.version}."
|
262
262
|
end
|
263
263
|
|
264
264
|
# Pushes the changes and tag to github
|
@@ -267,7 +267,7 @@ module GithubGem
|
|
267
267
|
end
|
268
268
|
|
269
269
|
def gemcutter_release_task
|
270
|
-
sh "gem", 'push', "pkg/#{
|
270
|
+
sh "gem", 'push', "pkg/#{gem_package_filename}.gem"
|
271
271
|
end
|
272
272
|
|
273
273
|
# Gem release task.
|
@@ -289,6 +289,14 @@ module GithubGem
|
|
289
289
|
FileList[test_pattern].any?
|
290
290
|
end
|
291
291
|
|
292
|
+
def gem_package_filename
|
293
|
+
"#{gemspec.name}-#{gemspec.version}#{platform_suffix}"
|
294
|
+
end
|
295
|
+
|
296
|
+
def platform_suffix
|
297
|
+
"-#{gemspec.platform}" unless gemspec.platform == 'ruby'
|
298
|
+
end
|
299
|
+
|
292
300
|
# Loads the gemspec file
|
293
301
|
def load_gemspec!
|
294
302
|
@gemspec = eval(File.read(@gemspec_file))
|
@@ -334,7 +342,7 @@ module GithubGem
|
|
334
342
|
|
335
343
|
# Reload the gemspec so the changes are incorporated
|
336
344
|
load_gemspec!
|
337
|
-
|
345
|
+
|
338
346
|
# Also mark the Gemfile.lock file as changed because of the new version.
|
339
347
|
modified_files << 'Gemfile.lock' if File.exist?(File.join(root_dir, 'Gemfile.lock'))
|
340
348
|
end
|
@@ -344,7 +352,7 @@ module GithubGem
|
|
344
352
|
def update_tasks_task
|
345
353
|
require 'net/https'
|
346
354
|
require 'uri'
|
347
|
-
|
355
|
+
|
348
356
|
uri = URI.parse('https://raw.github.com/wvanbergen/github-gem/master/tasks/github-gem.rake')
|
349
357
|
http = Net::HTTP.new(uri.host, uri.port)
|
350
358
|
http.use_ssl = true
|
metadata
CHANGED
@@ -1,154 +1,168 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: mordor
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 2
|
9
|
-
- 20
|
10
|
-
version: 0.2.20
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.3.5
|
11
5
|
platform: ruby
|
12
|
-
authors:
|
6
|
+
authors:
|
13
7
|
- Jan-Willem Koelewijn
|
14
8
|
- Dirkjan Bussink
|
15
|
-
autorequire:
|
9
|
+
autorequire:
|
16
10
|
bindir: bin
|
17
11
|
cert_chain: []
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
version_requirements: &id001 !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
|
-
requirements:
|
12
|
+
date: 2020-07-28 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: extlib
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
27
18
|
- - ">="
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
|
30
|
-
|
31
|
-
- 0
|
32
|
-
version: "0"
|
33
|
-
prerelease: false
|
34
|
-
type: :development
|
35
|
-
requirement: *id001
|
36
|
-
- !ruby/object:Gem::Dependency
|
37
|
-
name: rspec
|
38
|
-
version_requirements: &id002 !ruby/object:Gem::Requirement
|
39
|
-
none: false
|
40
|
-
requirements:
|
41
|
-
- - ~>
|
42
|
-
- !ruby/object:Gem::Version
|
43
|
-
hash: 3
|
44
|
-
segments:
|
45
|
-
- 2
|
46
|
-
- 0
|
47
|
-
version: "2.0"
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '0'
|
21
|
+
type: :runtime
|
48
22
|
prerelease: false
|
49
|
-
|
50
|
-
|
51
|
-
- !ruby/object:Gem::Dependency
|
52
|
-
name: json
|
53
|
-
version_requirements: &id003 !ruby/object:Gem::Requirement
|
54
|
-
none: false
|
55
|
-
requirements:
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
56
25
|
- - ">="
|
57
|
-
- !ruby/object:Gem::Version
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '0'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: json
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - "~>"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: 2.3.0
|
35
|
+
type: :runtime
|
62
36
|
prerelease: false
|
63
|
-
|
64
|
-
|
65
|
-
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - "~>"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: 2.3.0
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: mongo
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - "<"
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: 2.0.0
|
49
|
+
type: :runtime
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - "<"
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: 2.0.0
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: rack-test
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
70
60
|
- - ">="
|
71
|
-
- !ruby/object:Gem::Version
|
72
|
-
|
73
|
-
|
74
|
-
- 0
|
75
|
-
version: "0"
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
type: :development
|
76
64
|
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: guard-rspec
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
77
|
type: :development
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
version_requirements: &id005 !ruby/object:Gem::Requirement
|
82
|
-
none: false
|
83
|
-
requirements:
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
84
81
|
- - ">="
|
85
|
-
- !ruby/object:Gem::Version
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
- !ruby/object:Gem::Dependency
|
85
|
+
name: rake
|
86
|
+
requirement: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - "~>"
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: 12.3.3
|
91
|
+
type: :development
|
90
92
|
prerelease: false
|
93
|
+
version_requirements: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - "~>"
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: 12.3.3
|
98
|
+
- !ruby/object:Gem::Dependency
|
99
|
+
name: rspec
|
100
|
+
requirement: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - "~>"
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '2.0'
|
105
|
+
- - "<"
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: '2.99'
|
91
108
|
type: :development
|
92
|
-
requirement: *id005
|
93
|
-
- !ruby/object:Gem::Dependency
|
94
|
-
name: extlib
|
95
|
-
version_requirements: &id006 !ruby/object:Gem::Requirement
|
96
|
-
none: false
|
97
|
-
requirements:
|
98
|
-
- - ">="
|
99
|
-
- !ruby/object:Gem::Version
|
100
|
-
hash: 3
|
101
|
-
segments:
|
102
|
-
- 0
|
103
|
-
version: "0"
|
104
109
|
prerelease: false
|
105
|
-
|
106
|
-
|
107
|
-
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
110
|
+
version_requirements: !ruby/object:Gem::Requirement
|
111
|
+
requirements:
|
112
|
+
- - "~>"
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: '2.0'
|
115
|
+
- - "<"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '2.99'
|
118
|
+
- !ruby/object:Gem::Dependency
|
119
|
+
name: rspec_junit_formatter
|
120
|
+
requirement: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
112
122
|
- - ">="
|
113
|
-
- !ruby/object:Gem::Version
|
114
|
-
|
115
|
-
|
116
|
-
- 0
|
117
|
-
version: "0"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
type: :development
|
118
126
|
prerelease: false
|
119
|
-
|
120
|
-
|
121
|
-
- !ruby/object:Gem::Dependency
|
122
|
-
name: json
|
123
|
-
version_requirements: &id008 !ruby/object:Gem::Requirement
|
124
|
-
none: false
|
125
|
-
requirements:
|
127
|
+
version_requirements: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
126
129
|
- - ">="
|
127
|
-
- !ruby/object:Gem::Version
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
- !ruby/object:Gem::Dependency
|
133
|
+
name: bson_ext
|
134
|
+
requirement: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
133
139
|
type: :runtime
|
134
|
-
|
135
|
-
|
136
|
-
|
140
|
+
prerelease: false
|
141
|
+
version_requirements: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
description: " Small gem to add MongoDB Resources, resources have attributes that
|
147
|
+
translate into document fields. When an attribute is declared, finders for the attribute
|
148
|
+
are added to the Resource automatically\n"
|
149
|
+
email:
|
137
150
|
- janwillem.koelewijn@nedap.com
|
138
151
|
- dirkjan.bussink@nedap.com
|
139
152
|
executables: []
|
140
|
-
|
141
|
-
|
142
|
-
|
153
|
+
extensions:
|
154
|
+
- ext/mkrf_conf.rb
|
143
155
|
extra_rdoc_files: []
|
144
|
-
|
145
|
-
|
146
|
-
- .gitignore
|
147
|
-
- .
|
156
|
+
files:
|
157
|
+
- ".circleci/config.yml"
|
158
|
+
- ".gitignore"
|
159
|
+
- CHANGES.md
|
148
160
|
- Gemfile
|
161
|
+
- Guardfile
|
149
162
|
- LICENSE
|
150
163
|
- README.md
|
151
164
|
- Rakefile
|
165
|
+
- ext/mkrf_conf.rb
|
152
166
|
- lib/mordor.rb
|
153
167
|
- lib/mordor/collection.rb
|
154
168
|
- lib/mordor/config.rb
|
@@ -161,39 +175,26 @@ files:
|
|
161
175
|
- spec/spec.opts
|
162
176
|
- spec/spec_helper.rb
|
163
177
|
- tasks/github-gem.rake
|
164
|
-
|
165
|
-
homepage: http://www.nedap.com
|
178
|
+
homepage: http://github.com/jwkoelewijn/mordor/
|
166
179
|
licenses: []
|
167
|
-
|
168
|
-
post_install_message:
|
180
|
+
metadata: {}
|
181
|
+
post_install_message:
|
169
182
|
rdoc_options: []
|
170
|
-
|
171
|
-
require_paths:
|
183
|
+
require_paths:
|
172
184
|
- lib
|
173
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
174
|
-
|
175
|
-
requirements:
|
185
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
186
|
+
requirements:
|
176
187
|
- - ">="
|
177
|
-
- !ruby/object:Gem::Version
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
version: "0"
|
182
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
183
|
-
none: false
|
184
|
-
requirements:
|
188
|
+
- !ruby/object:Gem::Version
|
189
|
+
version: '0'
|
190
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
191
|
+
requirements:
|
185
192
|
- - ">="
|
186
|
-
- !ruby/object:Gem::Version
|
187
|
-
|
188
|
-
segments:
|
189
|
-
- 0
|
190
|
-
version: "0"
|
193
|
+
- !ruby/object:Gem::Version
|
194
|
+
version: '0'
|
191
195
|
requirements: []
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
signing_key:
|
196
|
-
specification_version: 3
|
196
|
+
rubygems_version: 3.0.8
|
197
|
+
signing_key:
|
198
|
+
specification_version: 4
|
197
199
|
summary: mordor
|
198
200
|
test_files: []
|
199
|
-
|
data/.travis.yml
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
language: ruby
|
2
|
-
|
3
|
-
jdk:
|
4
|
-
- oraclejdk7
|
5
|
-
|
6
|
-
services:
|
7
|
-
- mongodb
|
8
|
-
|
9
|
-
rvm:
|
10
|
-
- 1.8.7
|
11
|
-
- 1.9.2
|
12
|
-
- 1.9.3
|
13
|
-
- jruby-18mode
|
14
|
-
- jruby-19mode
|
15
|
-
- rbx-18mode
|
16
|
-
- rbx-19mode
|
17
|
-
|
18
|
-
matrix:
|
19
|
-
allow_failures:
|
20
|
-
- rvm: rbx-19mode
|
21
|
-
- rvm: rbx-18mode
|