mongoTools 0.0.1 → 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.
- data/.gitignore +45 -0
- data/Gemfile +9 -0
- data/Gemfile.lock +90 -0
- data/Guardfile +8 -0
- data/lib/md5.rb +45 -0
- data/lib/mongoTools.rb +1 -0
- data/mongoTools.gemspec +15 -0
- data/readme.md +45 -0
- data/spec/lib/md5_spec.rb +56 -0
- data/spec/mongoid.yml +12 -0
- data/spec/spec_helper.rb +6 -0
- metadata +14 -3
data/.gitignore
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
./log/*
|
2
|
+
log/*.log
|
3
|
+
log/development.log
|
4
|
+
.DS_Store
|
5
|
+
doc/api
|
6
|
+
doc/app
|
7
|
+
coverage
|
8
|
+
db/*.sqlite3
|
9
|
+
db/development_structure.sql
|
10
|
+
public/uploads
|
11
|
+
spec/dummy/log
|
12
|
+
spec/dummy/tmp
|
13
|
+
spec/dummy/public/system/images
|
14
|
+
spec/dummy/puplic/assets/*
|
15
|
+
spec/dummy/public/system/uploads/*
|
16
|
+
spec/dummy/public/system/*
|
17
|
+
spec/dummy/public/uploads
|
18
|
+
spec/dummy/log*
|
19
|
+
spec/dummy/tmp*
|
20
|
+
index/*
|
21
|
+
*.swp
|
22
|
+
*.swo
|
23
|
+
.idea/
|
24
|
+
.idea/**/*
|
25
|
+
nbproject/*
|
26
|
+
*.war
|
27
|
+
db/schema.rb
|
28
|
+
tmp/*
|
29
|
+
wMake.bat
|
30
|
+
etc/web.xml
|
31
|
+
build/
|
32
|
+
build/*
|
33
|
+
.bundle/
|
34
|
+
~/
|
35
|
+
~/*
|
36
|
+
*.knob
|
37
|
+
tmp
|
38
|
+
mysession.vi*
|
39
|
+
ruby-uuid
|
40
|
+
localhistory
|
41
|
+
test
|
42
|
+
prod
|
43
|
+
*.png
|
44
|
+
site/dev/images/galleries
|
45
|
+
*.gem
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
mongoTools (0.0.1)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: http://rubygems.org/
|
8
|
+
specs:
|
9
|
+
activemodel (4.1.4)
|
10
|
+
activesupport (= 4.1.4)
|
11
|
+
builder (~> 3.1)
|
12
|
+
activesupport (4.1.4)
|
13
|
+
i18n (~> 0.6, >= 0.6.9)
|
14
|
+
json (~> 1.7, >= 1.7.7)
|
15
|
+
minitest (~> 5.1)
|
16
|
+
thread_safe (~> 0.1)
|
17
|
+
tzinfo (~> 1.1)
|
18
|
+
bson (2.3.0)
|
19
|
+
builder (3.2.2)
|
20
|
+
celluloid (0.15.2)
|
21
|
+
timers (~> 1.1.0)
|
22
|
+
coderay (1.1.0)
|
23
|
+
connection_pool (2.0.0)
|
24
|
+
diff-lcs (1.2.5)
|
25
|
+
ffi (1.9.3)
|
26
|
+
formatador (0.2.5)
|
27
|
+
guard (2.6.1)
|
28
|
+
formatador (>= 0.2.4)
|
29
|
+
listen (~> 2.7)
|
30
|
+
lumberjack (~> 1.0)
|
31
|
+
pry (>= 0.9.12)
|
32
|
+
thor (>= 0.18.1)
|
33
|
+
guard-rspec (4.3.1)
|
34
|
+
guard (~> 2.1)
|
35
|
+
rspec (>= 2.14, < 4.0)
|
36
|
+
i18n (0.6.11)
|
37
|
+
json (1.8.1)
|
38
|
+
listen (2.7.9)
|
39
|
+
celluloid (>= 0.15.2)
|
40
|
+
rb-fsevent (>= 0.9.3)
|
41
|
+
rb-inotify (>= 0.9)
|
42
|
+
lumberjack (1.0.9)
|
43
|
+
method_source (0.8.2)
|
44
|
+
minitest (5.4.0)
|
45
|
+
mongoid (4.0.0)
|
46
|
+
activemodel (~> 4.0)
|
47
|
+
moped (~> 2.0.0)
|
48
|
+
origin (~> 2.1)
|
49
|
+
tzinfo (>= 0.3.37)
|
50
|
+
moped (2.0.0)
|
51
|
+
bson (~> 2.2)
|
52
|
+
connection_pool (~> 2.0)
|
53
|
+
optionable (~> 0.2.0)
|
54
|
+
optionable (0.2.0)
|
55
|
+
origin (2.1.1)
|
56
|
+
pry (0.10.0)
|
57
|
+
coderay (~> 1.1.0)
|
58
|
+
method_source (~> 0.8.1)
|
59
|
+
slop (~> 3.4)
|
60
|
+
rb-fsevent (0.9.4)
|
61
|
+
rb-inotify (0.9.5)
|
62
|
+
ffi (>= 0.5.0)
|
63
|
+
rspec (3.0.0)
|
64
|
+
rspec-core (~> 3.0.0)
|
65
|
+
rspec-expectations (~> 3.0.0)
|
66
|
+
rspec-mocks (~> 3.0.0)
|
67
|
+
rspec-core (3.0.3)
|
68
|
+
rspec-support (~> 3.0.0)
|
69
|
+
rspec-expectations (3.0.3)
|
70
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
71
|
+
rspec-support (~> 3.0.0)
|
72
|
+
rspec-mocks (3.0.3)
|
73
|
+
rspec-support (~> 3.0.0)
|
74
|
+
rspec-support (3.0.3)
|
75
|
+
slop (3.6.0)
|
76
|
+
thor (0.19.1)
|
77
|
+
thread_safe (0.3.4)
|
78
|
+
timers (1.1.0)
|
79
|
+
tzinfo (1.2.1)
|
80
|
+
thread_safe (~> 0.1)
|
81
|
+
|
82
|
+
PLATFORMS
|
83
|
+
ruby
|
84
|
+
|
85
|
+
DEPENDENCIES
|
86
|
+
guard
|
87
|
+
guard-rspec
|
88
|
+
mongoTools!
|
89
|
+
mongoid
|
90
|
+
rspec
|
data/Guardfile
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
# A sample Guardfile
|
2
|
+
# More info at https://github.com/guard/guard#readme
|
3
|
+
notification :tmux, display_message: true
|
4
|
+
guard :rspec , cmd: "rspec" do
|
5
|
+
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
|
6
|
+
watch('spec/spec_helper.rb') { "spec" }
|
7
|
+
watch(%r{^spec/.+_spec\.rb$})
|
8
|
+
end
|
data/lib/md5.rb
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'mongoid'
|
2
|
+
module MongoTools
|
3
|
+
|
4
|
+
|
5
|
+
def md5_create(field_names)
|
6
|
+
calc_md5(concat_string(field_names,""))
|
7
|
+
end
|
8
|
+
|
9
|
+
|
10
|
+
def concat_string(field_names,start_with)
|
11
|
+
retString = start_with
|
12
|
+
field_names.each do |field|
|
13
|
+
field_content = read_attribute(field).inspect
|
14
|
+
retString = retString + field_content
|
15
|
+
end
|
16
|
+
retString
|
17
|
+
end
|
18
|
+
|
19
|
+
##aufter that method the element exists in al cases.
|
20
|
+
#it returns true if the item has to be created
|
21
|
+
#otherwise false
|
22
|
+
|
23
|
+
def find_or_create_with_md5(elements)
|
24
|
+
md5_string = md5_create(elements)
|
25
|
+
if !self.class.where(md5: md5_string).exists?
|
26
|
+
self.md5 = md5_string
|
27
|
+
self.save!
|
28
|
+
return true
|
29
|
+
else
|
30
|
+
return false
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
def calc_md5(md_string)
|
37
|
+
ret=Digest::MD5.hexdigest(md_string)
|
38
|
+
ret
|
39
|
+
end
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
Mongoid::Document.send(:include, MongoTools)
|
data/lib/mongoTools.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'md5'
|
data/mongoTools.gemspec
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = 'mongoTools'
|
3
|
+
s.version = '0.0.2'
|
4
|
+
s.date = '2014-08-02'
|
5
|
+
s.summary = "At the moment only md5 saver"
|
6
|
+
s.description = "only saves or create when the md5 of some fields has changed"
|
7
|
+
s.authors = ["Erhard Karger"]
|
8
|
+
s.email = 'erhard@kargers.org'
|
9
|
+
s.homepage = 'http://rubygems.org/gems/mongoTools'
|
10
|
+
s.license = 'MIT'
|
11
|
+
git_files = `git ls-files`.split("\n") rescue ''
|
12
|
+
s.files = git_files
|
13
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
14
|
+
s.require_paths = ["lib"]
|
15
|
+
end
|
data/readme.md
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
MongoTools
|
2
|
+
===
|
3
|
+
|
4
|
+
Install
|
5
|
+
-------
|
6
|
+
gem install mongoTools
|
7
|
+
|
8
|
+
Example
|
9
|
+
-------
|
10
|
+
require "mongoTools"
|
11
|
+
|
12
|
+
|
13
|
+
TestMd5Object.delete_all()
|
14
|
+
##call it more times
|
15
|
+
@to.find_or_create_with_md5(["email","adress","name","groups"])
|
16
|
+
@to.find_or_create_with_md5(["email","adress","name","groups"])
|
17
|
+
@to.find_or_create_with_md5(["email","adress","name","groups"])
|
18
|
+
|
19
|
+
##Test :
|
20
|
+
expect(TestMd5Object.count()).to eq(1)
|
21
|
+
|
22
|
+
|
23
|
+
Look at the specs to see examples
|
24
|
+
|
25
|
+
|
26
|
+
current project status
|
27
|
+
----------------------
|
28
|
+
Work in progress just started
|
29
|
+
This project is tthe place for all I need and is not in mongo
|
30
|
+
At the moment its a md5 function.
|
31
|
+
the md5 function gets an Array of fields and creates a md5 chesum of the content
|
32
|
+
It only adds a new record to the db when the md5 checksum of the specific fields has changed.
|
33
|
+
Otherwise it leaves the db untouched.
|
34
|
+
You need a field in the collection : md5, :type String
|
35
|
+
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
Licence:
|
42
|
+
MIT
|
43
|
+
|
44
|
+
Author:
|
45
|
+
Erhard Karger
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'mongoid'
|
3
|
+
|
4
|
+
Mongoid.load!(File.join(File.dirname(__FILE__),"../mongoid.yml"), :test)
|
5
|
+
|
6
|
+
describe "md5_tools" do
|
7
|
+
before(:each) do
|
8
|
+
class TestMd5Object
|
9
|
+
include Mongoid::Document
|
10
|
+
include Mongoid::Attributes::Dynamic
|
11
|
+
field :email, type: String
|
12
|
+
field :adress, type: String
|
13
|
+
field :name, type: String
|
14
|
+
field :groups, type: Array
|
15
|
+
field :md5, type: String
|
16
|
+
end
|
17
|
+
@to = TestMd5Object.new({email: "test@email.com", adress: "New York", name: "Erhard", groups:["football","icehokey"]})
|
18
|
+
end
|
19
|
+
it "should create a md5 over some fields" do
|
20
|
+
md5 = @to.md5_create(["email","adress"])
|
21
|
+
puts md5
|
22
|
+
expect(md5).to eq("2c36c501b5fd85afc39084bf94674214")
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should create a long string of a field structure" do
|
26
|
+
longString= @to.concat_string(["email","adress","name","groups"],"")
|
27
|
+
expected_result="\"test@email.com\"\"New York\"\"Erhard\"[\"football\", \"icehokey\"]"
|
28
|
+
expect(longString).to eq(expected_result)
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should save a record" do
|
32
|
+
TestMd5Object.delete_all()
|
33
|
+
@to.find_or_create_with_md5(["email","adress","name","groups"])
|
34
|
+
expect(TestMd5Object.count()).to eq(1)
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should not save a record and give back the object_id of the found md5" do
|
38
|
+
TestMd5Object.delete_all()
|
39
|
+
##call it more times
|
40
|
+
@to.find_or_create_with_md5(["email","adress","name","groups"])
|
41
|
+
@to.find_or_create_with_md5(["email","adress","name","groups"])
|
42
|
+
@to.find_or_create_with_md5(["email","adress","name","groups"])
|
43
|
+
expect(TestMd5Object.count()).to eq(1)
|
44
|
+
end
|
45
|
+
|
46
|
+
|
47
|
+
it "should be full the md5 field..." do
|
48
|
+
TestMd5Object.delete_all()
|
49
|
+
@to.find_or_create_with_md5(["email","adress","name","groups"])
|
50
|
+
expect(@to.md5).to eq(@to.md5_create(["email","adress","name","groups"]))
|
51
|
+
end
|
52
|
+
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
|
data/spec/mongoid.yml
ADDED
data/spec/spec_helper.rb
ADDED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongoTools
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,14 +9,25 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-08-
|
12
|
+
date: 2014-08-02 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: only saves or create when the md5 of some fields has changed
|
15
15
|
email: erhard@kargers.org
|
16
16
|
executables: []
|
17
17
|
extensions: []
|
18
18
|
extra_rdoc_files: []
|
19
|
-
files:
|
19
|
+
files:
|
20
|
+
- .gitignore
|
21
|
+
- Gemfile
|
22
|
+
- Gemfile.lock
|
23
|
+
- Guardfile
|
24
|
+
- lib/md5.rb
|
25
|
+
- lib/mongoTools.rb
|
26
|
+
- mongoTools.gemspec
|
27
|
+
- readme.md
|
28
|
+
- spec/lib/md5_spec.rb
|
29
|
+
- spec/mongoid.yml
|
30
|
+
- spec/spec_helper.rb
|
20
31
|
homepage: http://rubygems.org/gems/mongoTools
|
21
32
|
licenses:
|
22
33
|
- MIT
|