modis 1.4.1-java
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 +16 -0
- data/.rubocop.yml +31 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +13 -0
- data/Gemfile +17 -0
- data/Gemfile.lock +89 -0
- data/LICENSE.txt +22 -0
- data/README.md +45 -0
- data/Rakefile +17 -0
- data/benchmark/bench.rb +65 -0
- data/benchmark/find.rb +62 -0
- data/benchmark/persistence.rb +82 -0
- data/benchmark/redis/connection/fakedis.rb +90 -0
- data/lib/modis.rb +41 -0
- data/lib/modis/attribute.rb +103 -0
- data/lib/modis/configuration.rb +14 -0
- data/lib/modis/errors.rb +16 -0
- data/lib/modis/finder.rb +76 -0
- data/lib/modis/index.rb +84 -0
- data/lib/modis/model.rb +47 -0
- data/lib/modis/persistence.rb +233 -0
- data/lib/modis/transaction.rb +13 -0
- data/lib/modis/version.rb +3 -0
- data/lib/tasks/quality.rake +41 -0
- data/modis.gemspec +32 -0
- data/spec/attribute_spec.rb +172 -0
- data/spec/errors_spec.rb +18 -0
- data/spec/finder_spec.rb +109 -0
- data/spec/index_spec.rb +84 -0
- data/spec/persistence_spec.rb +319 -0
- data/spec/spec_helper.rb +24 -0
- data/spec/support/simplecov_helper.rb +23 -0
- data/spec/support/simplecov_quality_formatter.rb +12 -0
- data/spec/transaction_spec.rb +16 -0
- data/spec/validations_spec.rb +49 -0
- metadata +173 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 3ad8fb8aa0b0141ffd6df420d2b7e32774a4754d
|
4
|
+
data.tar.gz: f30e5fb8580408078fa08fb12d5add506c8e97a6
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 21da63c7a0b620362102619b02ee930c4662ad3274d113dd8aca58e24822d24a8770d73bd2f6c6fddafb5036d489f23816456f95bdff6742dee8b03a667dc7f8
|
7
|
+
data.tar.gz: 023bb6a7925f9215793abaa02f5187cc0bcd2954f905d89d3fbe402207e1d0bfda8aba079b1734a270bd7fa563165ae1df6bad488dde88db89bf78284f5c0da4
|
data/.gitignore
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
AllCops:
|
2
|
+
Exclude:
|
3
|
+
- modis.gemspec
|
4
|
+
- vendor/**/*
|
5
|
+
|
6
|
+
LineLength:
|
7
|
+
Enabled: false
|
8
|
+
|
9
|
+
StringLiterals:
|
10
|
+
Enabled: false
|
11
|
+
|
12
|
+
Documentation:
|
13
|
+
Enabled: false
|
14
|
+
|
15
|
+
MethodLength:
|
16
|
+
Enabled: false
|
17
|
+
|
18
|
+
ClassLength:
|
19
|
+
Enabled: false
|
20
|
+
|
21
|
+
CyclomaticComplexity:
|
22
|
+
Enabled: false
|
23
|
+
|
24
|
+
Style/SignalException:
|
25
|
+
EnforcedStyle: only_raise
|
26
|
+
|
27
|
+
Style/NumericLiterals:
|
28
|
+
Enabled: false
|
29
|
+
|
30
|
+
Metrics/AbcSize:
|
31
|
+
Max: 25
|
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
modis
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby-2.2.0
|
data/.travis.yml
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
sudo: false
|
2
|
+
services:
|
3
|
+
- redis-server
|
4
|
+
language: ruby
|
5
|
+
rvm:
|
6
|
+
- 2.0.0
|
7
|
+
- 2.1.5
|
8
|
+
- 2.2.0
|
9
|
+
- jruby-1.7.18
|
10
|
+
- rbx-2.5.0
|
11
|
+
env:
|
12
|
+
global:
|
13
|
+
secure: LrTz0Pq2ibNZuKDhdzcrvEUSNxUpPopEq9aJeCxy3UpV0v4vpHBtWV0S6zofvf98g/RkZ6cGI1u+0H578dHgE6pWTo+iR8LAwqPKofrFIWRkeo+M77Vs5swahb3mQyPOcig1hfVWDm25MsojePYm70eBIcBU55NWImtdePXfiU0=
|
data/Gemfile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
gem 'rake'
|
4
|
+
gem 'rspec'
|
5
|
+
|
6
|
+
platform :mri do
|
7
|
+
gem 'codeclimate-test-reporter', require: nil
|
8
|
+
gem 'cane'
|
9
|
+
gem 'rubocop', require: false
|
10
|
+
gem 'simplecov', require: false
|
11
|
+
end
|
12
|
+
|
13
|
+
platform :mri_21 do
|
14
|
+
gem 'stackprof'
|
15
|
+
end
|
16
|
+
|
17
|
+
gemspec
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
modis (1.4.1-java)
|
5
|
+
activemodel (>= 3.0)
|
6
|
+
activesupport (>= 3.0)
|
7
|
+
connection_pool (>= 2)
|
8
|
+
hiredis (>= 0.5)
|
9
|
+
msgpack-jruby
|
10
|
+
redis (>= 3.0)
|
11
|
+
|
12
|
+
GEM
|
13
|
+
remote: https://rubygems.org/
|
14
|
+
specs:
|
15
|
+
activemodel (4.2.0)
|
16
|
+
activesupport (= 4.2.0)
|
17
|
+
builder (~> 3.1)
|
18
|
+
activesupport (4.2.0)
|
19
|
+
i18n (~> 0.7)
|
20
|
+
json (~> 1.7, >= 1.7.7)
|
21
|
+
minitest (~> 5.1)
|
22
|
+
thread_safe (~> 0.3, >= 0.3.4)
|
23
|
+
tzinfo (~> 1.1)
|
24
|
+
ast (2.0.0)
|
25
|
+
astrolabe (1.3.0)
|
26
|
+
parser (>= 2.2.0.pre.3, < 3.0)
|
27
|
+
builder (3.2.2)
|
28
|
+
cane (2.6.2)
|
29
|
+
parallel
|
30
|
+
codeclimate-test-reporter (0.4.5)
|
31
|
+
simplecov (>= 0.7.1, < 1.0.0)
|
32
|
+
connection_pool (2.1.0)
|
33
|
+
diff-lcs (1.2.5)
|
34
|
+
docile (1.1.5)
|
35
|
+
hiredis (0.5.2-java)
|
36
|
+
i18n (0.7.0)
|
37
|
+
json (1.8.2-java)
|
38
|
+
minitest (5.5.1)
|
39
|
+
msgpack-jruby (1.4.0-java)
|
40
|
+
multi_json (1.10.1)
|
41
|
+
parallel (1.3.3)
|
42
|
+
parser (2.2.0.2)
|
43
|
+
ast (>= 1.1, < 3.0)
|
44
|
+
powerpack (0.0.9)
|
45
|
+
rainbow (2.0.0)
|
46
|
+
rake (10.4.2)
|
47
|
+
redis (3.2.0)
|
48
|
+
rspec (3.1.0)
|
49
|
+
rspec-core (~> 3.1.0)
|
50
|
+
rspec-expectations (~> 3.1.0)
|
51
|
+
rspec-mocks (~> 3.1.0)
|
52
|
+
rspec-core (3.1.7)
|
53
|
+
rspec-support (~> 3.1.0)
|
54
|
+
rspec-expectations (3.1.2)
|
55
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
56
|
+
rspec-support (~> 3.1.0)
|
57
|
+
rspec-mocks (3.1.3)
|
58
|
+
rspec-support (~> 3.1.0)
|
59
|
+
rspec-support (3.1.2)
|
60
|
+
rubocop (0.28.0)
|
61
|
+
astrolabe (~> 1.3)
|
62
|
+
parser (>= 2.2.0.pre.7, < 3.0)
|
63
|
+
powerpack (~> 0.0.6)
|
64
|
+
rainbow (>= 1.99.1, < 3.0)
|
65
|
+
ruby-progressbar (~> 1.4)
|
66
|
+
ruby-progressbar (1.7.1)
|
67
|
+
simplecov (0.9.1)
|
68
|
+
docile (~> 1.1.0)
|
69
|
+
multi_json (~> 1.0)
|
70
|
+
simplecov-html (~> 0.8.0)
|
71
|
+
simplecov-html (0.8.0)
|
72
|
+
stackprof (0.2.7)
|
73
|
+
thread_safe (0.3.4-java)
|
74
|
+
tzinfo (1.2.2)
|
75
|
+
thread_safe (~> 0.1)
|
76
|
+
|
77
|
+
PLATFORMS
|
78
|
+
java
|
79
|
+
ruby
|
80
|
+
|
81
|
+
DEPENDENCIES
|
82
|
+
cane
|
83
|
+
codeclimate-test-reporter
|
84
|
+
modis!
|
85
|
+
rake
|
86
|
+
rspec
|
87
|
+
rubocop
|
88
|
+
simplecov
|
89
|
+
stackprof
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Ian Leitch
|
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,45 @@
|
|
1
|
+
[](http://travis-ci.org/ileitch/modis)
|
2
|
+
[](https://codeclimate.com/github/ileitch/modis)
|
3
|
+
[](https://codeclimate.com/github/ileitch/modis)
|
4
|
+
|
5
|
+
# Modis
|
6
|
+
|
7
|
+
ActiveModel + Redis with the aim to mimic ActiveRecord where possible.
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
gem 'modis'
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install modis
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
class MyModel
|
27
|
+
include Modis::Models
|
28
|
+
attribute :name, String
|
29
|
+
attribute :age, Integer
|
30
|
+
end
|
31
|
+
|
32
|
+
MyModel.create!(:name => 'Ian', :age => 28)
|
33
|
+
```
|
34
|
+
|
35
|
+
## Supported Features
|
36
|
+
|
37
|
+
TODO.
|
38
|
+
|
39
|
+
## Contributing
|
40
|
+
|
41
|
+
1. Fork it
|
42
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
43
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
44
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
45
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require "rake"
|
2
|
+
require "bundler/gem_tasks"
|
3
|
+
require "rspec/core/rake_task"
|
4
|
+
Dir["lib/tasks/*.rake"].each { |rake| load rake }
|
5
|
+
|
6
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
7
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
8
|
+
spec.rspec_opts = ['--backtrace']
|
9
|
+
end
|
10
|
+
|
11
|
+
if ENV['TRAVIS'] && ENV['QUALITY'] == 'false'
|
12
|
+
task default: 'spec'
|
13
|
+
elsif RUBY_VERSION > '1.9' && defined?(RUBY_ENGINE) && RUBY_ENGINE == 'ruby'
|
14
|
+
task default: 'spec:quality'
|
15
|
+
else
|
16
|
+
task default: 'spec'
|
17
|
+
end
|
data/benchmark/bench.rb
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'stackprof'
|
2
|
+
require 'benchmark'
|
3
|
+
|
4
|
+
$LOAD_PATH.unshift('.')
|
5
|
+
require 'lib/modis'
|
6
|
+
|
7
|
+
puts "Profiler enabled." if ENV['PROFILE']
|
8
|
+
|
9
|
+
Modis.configure do |config|
|
10
|
+
config.namespace = 'modis_benchmark'
|
11
|
+
end
|
12
|
+
|
13
|
+
class Bench
|
14
|
+
def self.run
|
15
|
+
bench = new
|
16
|
+
yield(bench)
|
17
|
+
bench._run
|
18
|
+
end
|
19
|
+
|
20
|
+
def initialize
|
21
|
+
@bms = []
|
22
|
+
@profiles = []
|
23
|
+
end
|
24
|
+
|
25
|
+
def report(name, &blk)
|
26
|
+
@bms << [name, blk]
|
27
|
+
end
|
28
|
+
|
29
|
+
def _run
|
30
|
+
Benchmark.bmbm do |x|
|
31
|
+
@bms.each do |name, blk|
|
32
|
+
x.report(name) do
|
33
|
+
with_profile(name, &blk)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
after
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def with_profile(name, &blk)
|
44
|
+
if ENV['PROFILE']
|
45
|
+
mode = :wall
|
46
|
+
out = "tmp/stackprof-#{mode}-#{name}.dump"
|
47
|
+
@profiles << out
|
48
|
+
StackProf.run(mode: mode, out: out, &blk)
|
49
|
+
else
|
50
|
+
blk.call
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def after
|
55
|
+
Modis.with_connection do |connection|
|
56
|
+
keys = connection.keys "#{Modis.config.namespace}:*"
|
57
|
+
connection.del(*keys) unless keys.empty?
|
58
|
+
end
|
59
|
+
|
60
|
+
return unless @profiles.any?
|
61
|
+
|
62
|
+
puts "\nProfiler dumps:"
|
63
|
+
@profiles.uniq.each { |dump| puts " * stackprof #{dump} --text" }
|
64
|
+
end
|
65
|
+
end
|
data/benchmark/find.rb
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
$LOAD_PATH.unshift('benchmark')
|
2
|
+
require 'bench'
|
3
|
+
|
4
|
+
require 'redis/connection/fakedis'
|
5
|
+
# Redis::Connection::Fakedis.start_recording
|
6
|
+
Redis::Connection::Fakedis.start_replay(:find)
|
7
|
+
Modis.redis_options = { driver: :fakedis }
|
8
|
+
|
9
|
+
class User
|
10
|
+
include Modis::Model
|
11
|
+
|
12
|
+
attribute :name, :string
|
13
|
+
attribute :age, :integer
|
14
|
+
attribute :percentage, :float
|
15
|
+
attribute :created_at, :timestamp
|
16
|
+
attribute :flag, :boolean
|
17
|
+
attribute :array, :array
|
18
|
+
attribute :hash, :hash
|
19
|
+
attribute :string_or_hash, [:string, :hash]
|
20
|
+
|
21
|
+
index :name
|
22
|
+
end
|
23
|
+
|
24
|
+
def create_user
|
25
|
+
User.create!(name: 'Test', age: 30, percentage: 50.0, created_at: Time.now,
|
26
|
+
flag: true, array: [1, 2, 3], hash: { k: :v }, string_or_hash: "an string")
|
27
|
+
end
|
28
|
+
|
29
|
+
user = create_user
|
30
|
+
|
31
|
+
n = 10_000
|
32
|
+
|
33
|
+
Bench.run do |b|
|
34
|
+
b.report(:find) do
|
35
|
+
n.times do
|
36
|
+
User.find(user.id)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
b.report(:where) do
|
41
|
+
n.times do
|
42
|
+
User.where(name: user.name)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
n = 1_000
|
48
|
+
i = 20
|
49
|
+
STDOUT.write "\n* Creating #{i} users for :where_multiple... "
|
50
|
+
STDOUT.flush
|
51
|
+
i.times { create_user }
|
52
|
+
puts "✔\n\n"
|
53
|
+
|
54
|
+
Bench.run do |b|
|
55
|
+
b.report(:where_multiple) do
|
56
|
+
n.times do
|
57
|
+
User.where(name: 'Test')
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
# Redis::Connection::Fakedis.stop_recording(:find)
|
@@ -0,0 +1,82 @@
|
|
1
|
+
$LOAD_PATH.unshift('benchmark')
|
2
|
+
require 'bench'
|
3
|
+
|
4
|
+
require 'redis/connection/fakedis'
|
5
|
+
# Redis::Connection::Fakedis.start_recording
|
6
|
+
Redis::Connection::Fakedis.start_replay(:persistence)
|
7
|
+
Modis.redis_options = { driver: :fakedis }
|
8
|
+
|
9
|
+
class User
|
10
|
+
include Modis::Model
|
11
|
+
|
12
|
+
attribute :name, :string, default: 'Test'
|
13
|
+
attribute :age, :integer
|
14
|
+
attribute :percentage, :float
|
15
|
+
attribute :created_at, :timestamp
|
16
|
+
attribute :flag, :boolean
|
17
|
+
attribute :array, :array
|
18
|
+
attribute :hash, :hash
|
19
|
+
attribute :string_or_hash, [:string, :hash]
|
20
|
+
|
21
|
+
index :name
|
22
|
+
end
|
23
|
+
|
24
|
+
def create_user
|
25
|
+
User.create!(name: 'Test', age: 30, percentage: 50.0, created_at: Time.now,
|
26
|
+
flag: true, array: [1, 2, 3], hash: { k: :v }, string_or_hash: "an string")
|
27
|
+
end
|
28
|
+
|
29
|
+
n = 10_000
|
30
|
+
|
31
|
+
Bench.run do |b|
|
32
|
+
b.report(:create) do
|
33
|
+
n.times do
|
34
|
+
create_user
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
b.report(:save) do
|
39
|
+
n.times do
|
40
|
+
user = User.new
|
41
|
+
user.name = 'Test'
|
42
|
+
user.age = 30
|
43
|
+
user.percentage = 50.0
|
44
|
+
user.created_at = Time.now
|
45
|
+
user.flag = true
|
46
|
+
user.array = [1, 2, 3]
|
47
|
+
user.hash = { k: :v }
|
48
|
+
user.string_or_hash = "an string"
|
49
|
+
user.save!
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
b.report(:initialize) do
|
54
|
+
n.times do
|
55
|
+
User.new(name: 'Test', age: 30, percentage: 50.0, created_at: Time.now,
|
56
|
+
flag: true, array: [1, 2, 3], hash: { k: :v }, string_or_hash: "an string")
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
b.report(:update_without_changes) do
|
61
|
+
user = create_user
|
62
|
+
n.times do
|
63
|
+
user.update_attributes!(name: user.name, age: user.age)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
b.report(:update_with_changes) do
|
68
|
+
user = create_user
|
69
|
+
n.times do |i|
|
70
|
+
user.update_attribute(:name, i.to_s)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
b.report(:reload) do
|
75
|
+
user = create_user
|
76
|
+
n.times do
|
77
|
+
user.reload
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
# Redis::Connection::Fakedis.stop_recording(:persistence)
|