matic 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +25 -8
- data/README.md +8 -3
- data/benchmarks/create_many_books.rb +32 -0
- data/le_fou.jpg +0 -0
- data/lib/matic.rb +5 -5
- data/lib/matic/version.rb +1 -1
- data/matic.gemspec +5 -4
- data/spec/support/faker.rb +1 -0
- data/spec/support/mongomatic.rb +6 -0
- metadata +45 -11
data/Gemfile.lock
CHANGED
@@ -1,27 +1,32 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
matic (0.2.
|
4
|
+
matic (0.2.1)
|
5
5
|
activemodel (~> 3.0.0)
|
6
6
|
activesupport (~> 3.0.0)
|
7
|
-
mongomatic (~> 0.
|
7
|
+
mongomatic (~> 0.7.0)
|
8
8
|
|
9
9
|
GEM
|
10
10
|
remote: http://rubygems.org/
|
11
11
|
specs:
|
12
|
-
activemodel (3.0.
|
13
|
-
activesupport (= 3.0.
|
12
|
+
activemodel (3.0.3)
|
13
|
+
activesupport (= 3.0.3)
|
14
14
|
builder (~> 2.1.2)
|
15
|
-
i18n (~> 0.4
|
16
|
-
activesupport (3.0.
|
15
|
+
i18n (~> 0.4)
|
16
|
+
activesupport (3.0.3)
|
17
|
+
archive-tar-minitar (0.5.2)
|
17
18
|
bson (1.1.2)
|
18
19
|
bson_ext (1.1.2)
|
19
20
|
builder (2.1.2)
|
21
|
+
columnize (0.3.2)
|
20
22
|
diff-lcs (1.1.2)
|
23
|
+
faker (0.3.1)
|
21
24
|
i18n (0.4.2)
|
25
|
+
linecache19 (0.5.11)
|
26
|
+
ruby_core_source (>= 0.1.4)
|
22
27
|
mongo (1.1.2)
|
23
28
|
bson (>= 1.1.1)
|
24
|
-
mongomatic (0.
|
29
|
+
mongomatic (0.7.3)
|
25
30
|
activesupport (>= 2.3.5)
|
26
31
|
bson (~> 1.1)
|
27
32
|
mongo (~> 1.1)
|
@@ -36,6 +41,16 @@ GEM
|
|
36
41
|
rspec-mocks (2.0.1)
|
37
42
|
rspec-core (~> 2.0.1)
|
38
43
|
rspec-expectations (~> 2.0.1)
|
44
|
+
ruby-debug-base19 (0.11.24)
|
45
|
+
columnize (>= 0.3.1)
|
46
|
+
linecache19 (>= 0.5.11)
|
47
|
+
ruby_core_source (>= 0.1.4)
|
48
|
+
ruby-debug19 (0.11.6)
|
49
|
+
columnize (>= 0.3.1)
|
50
|
+
linecache19 (>= 0.5.11)
|
51
|
+
ruby-debug-base19 (>= 0.11.19)
|
52
|
+
ruby_core_source (0.1.4)
|
53
|
+
archive-tar-minitar (>= 0.5.2)
|
39
54
|
|
40
55
|
PLATFORMS
|
41
56
|
ruby
|
@@ -44,7 +59,9 @@ DEPENDENCIES
|
|
44
59
|
activemodel (~> 3.0.0)
|
45
60
|
activesupport (~> 3.0.0)
|
46
61
|
bson_ext (~> 1.1.0)
|
62
|
+
faker (~> 0.3.1)
|
47
63
|
matic!
|
48
|
-
mongomatic (~> 0.
|
64
|
+
mongomatic (~> 0.7.0)
|
49
65
|
rake (~> 0.8.7)
|
50
66
|
rspec (~> 2.0.0)
|
67
|
+
ruby-debug19 (~> 0.11.0)
|
data/README.md
CHANGED
@@ -1,7 +1,12 @@
|
|
1
1
|
# Matic
|
2
2
|
|
3
|
-
Matic
|
4
|
-
|
3
|
+
Matic is a dirtier Mongomatic.
|
4
|
+
|
5
|
+
Matic adds attribute accessors and dirty tracking to Mongomatic,
|
6
|
+
defaults the collection name to the plural of the class name, and
|
7
|
+
optionally shortens field names saved to MongoDB.
|
8
|
+
|
9
|
+
![Matic](http://github.com/papercavalier/matic/raw/master/le_fou.jpg)
|
5
10
|
|
6
11
|
## Examples
|
7
12
|
|
@@ -32,7 +37,7 @@ optionally shortens field names to optimize storing and indexing.
|
|
32
37
|
person.previous_changes["first_name"]
|
33
38
|
=> [nil, "John"]
|
34
39
|
|
35
|
-
|
40
|
+
A model with short field names:
|
36
41
|
|
37
42
|
class Person < Mongomatic::Base
|
38
43
|
include Matic
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'benchmark'
|
2
|
+
require File.expand_path("../../spec/spec_helper", __FILE__)
|
3
|
+
|
4
|
+
print "How many books would you like me to create, sir? "
|
5
|
+
many = STDIN.gets.to_i
|
6
|
+
|
7
|
+
Benchmark.bmbm do |x|
|
8
|
+
|
9
|
+
Book.drop
|
10
|
+
|
11
|
+
x.report("mongomatic") do
|
12
|
+
many.times do
|
13
|
+
book = Book.new
|
14
|
+
book["t"] = Faker::Company.catch_phrase
|
15
|
+
book["a"] = Faker::Name.name
|
16
|
+
book["p"] = Faker::Company.name
|
17
|
+
book.insert
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
Book.drop
|
22
|
+
|
23
|
+
x.report("matic") do
|
24
|
+
many.times do
|
25
|
+
book = Book.new
|
26
|
+
book.title = Faker::Company.catch_phrase
|
27
|
+
book.authors = Faker::Name.name
|
28
|
+
book.publisher = Faker::Company.name
|
29
|
+
book.insert
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/le_fou.jpg
ADDED
Binary file
|
data/lib/matic.rb
CHANGED
@@ -11,17 +11,17 @@ module Matic
|
|
11
11
|
|
12
12
|
def fields(*attrs)
|
13
13
|
if attrs.first.is_a? Hash
|
14
|
-
attrs.first.each { |
|
14
|
+
attrs.first.each { |n, f| define_accessors(n, f) }
|
15
15
|
define_attribute_methods(attrs.first.keys)
|
16
16
|
else
|
17
|
-
attrs.each { |
|
17
|
+
attrs.each { |n| define_accessors(n) }
|
18
18
|
define_attribute_methods(attrs)
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
22
|
private
|
23
23
|
|
24
|
-
def
|
24
|
+
def define_accessors(attr_name, attr_field=nil)
|
25
25
|
attr_field ||= attr_name
|
26
26
|
|
27
27
|
define_method(attr_name) do
|
@@ -39,11 +39,11 @@ module Matic
|
|
39
39
|
end
|
40
40
|
|
41
41
|
def insert(opts={})
|
42
|
-
|
42
|
+
super && clear_changes
|
43
43
|
end
|
44
44
|
|
45
45
|
def update(opts={}, update_doc=@doc)
|
46
|
-
|
46
|
+
super && clear_changes
|
47
47
|
end
|
48
48
|
|
49
49
|
def save
|
data/lib/matic/version.rb
CHANGED
data/matic.gemspec
CHANGED
@@ -9,8 +9,8 @@ Gem::Specification.new do |s|
|
|
9
9
|
s.authors = ["Hakan Ensari", "Gerhard Lazu"]
|
10
10
|
s.email = ["code@papercavalier.com"]
|
11
11
|
s.homepage = "http://github.com/papercavalier/matic"
|
12
|
-
s.summary = %q{
|
13
|
-
s.description = %q{Matic adds attribute accessors and dirty tracking to Mongomatic.}
|
12
|
+
s.summary = %q{A dirtier Mongomatic}
|
13
|
+
s.description = %q{Matic adds attribute accessors and dirty tracking to Mongomatic and optionally shortens field names saved to MongoDB.}
|
14
14
|
|
15
15
|
s.rubyforge_project = "matic"
|
16
16
|
|
@@ -19,13 +19,14 @@ Gem::Specification.new do |s|
|
|
19
19
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
20
|
s.require_paths = ["lib"]
|
21
21
|
|
22
|
-
s.add_dependency("mongomatic", "~> 0.
|
22
|
+
s.add_dependency("mongomatic", "~> 0.7.0")
|
23
23
|
s.add_dependency("activemodel", "~> 3.0.0")
|
24
24
|
s.add_dependency("activesupport", "~> 3.0.0")
|
25
25
|
s.add_development_dependency("bson_ext", "~> 1.1.0")
|
26
|
+
s.add_development_dependency("faker", "~> 0.3.1")
|
26
27
|
s.add_development_dependency("rake", "~> 0.8.7")
|
27
28
|
s.add_development_dependency("rspec", "~> 2.0.0")
|
28
|
-
if
|
29
|
+
if RUBY_VERSION.include?("1.9")
|
29
30
|
s.add_development_dependency("ruby-debug19", "~> 0.11.0")
|
30
31
|
end
|
31
32
|
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require "faker"
|
data/spec/support/mongomatic.rb
CHANGED
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 2
|
8
|
-
-
|
9
|
-
version: 0.2.
|
8
|
+
- 1
|
9
|
+
version: 0.2.1
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Hakan Ensari
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-11-
|
18
|
+
date: 2010-11-22 00:00:00 +00:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -28,9 +28,9 @@ dependencies:
|
|
28
28
|
- !ruby/object:Gem::Version
|
29
29
|
segments:
|
30
30
|
- 0
|
31
|
-
-
|
31
|
+
- 7
|
32
32
|
- 0
|
33
|
-
version: 0.
|
33
|
+
version: 0.7.0
|
34
34
|
type: :runtime
|
35
35
|
version_requirements: *id001
|
36
36
|
- !ruby/object:Gem::Dependency
|
@@ -79,9 +79,24 @@ dependencies:
|
|
79
79
|
type: :development
|
80
80
|
version_requirements: *id004
|
81
81
|
- !ruby/object:Gem::Dependency
|
82
|
-
name:
|
82
|
+
name: faker
|
83
83
|
prerelease: false
|
84
84
|
requirement: &id005 !ruby/object:Gem::Requirement
|
85
|
+
none: false
|
86
|
+
requirements:
|
87
|
+
- - ~>
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
segments:
|
90
|
+
- 0
|
91
|
+
- 3
|
92
|
+
- 1
|
93
|
+
version: 0.3.1
|
94
|
+
type: :development
|
95
|
+
version_requirements: *id005
|
96
|
+
- !ruby/object:Gem::Dependency
|
97
|
+
name: rake
|
98
|
+
prerelease: false
|
99
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
85
100
|
none: false
|
86
101
|
requirements:
|
87
102
|
- - ~>
|
@@ -92,11 +107,11 @@ dependencies:
|
|
92
107
|
- 7
|
93
108
|
version: 0.8.7
|
94
109
|
type: :development
|
95
|
-
version_requirements: *
|
110
|
+
version_requirements: *id006
|
96
111
|
- !ruby/object:Gem::Dependency
|
97
112
|
name: rspec
|
98
113
|
prerelease: false
|
99
|
-
requirement: &
|
114
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
100
115
|
none: false
|
101
116
|
requirements:
|
102
117
|
- - ~>
|
@@ -107,8 +122,23 @@ dependencies:
|
|
107
122
|
- 0
|
108
123
|
version: 2.0.0
|
109
124
|
type: :development
|
110
|
-
version_requirements: *
|
111
|
-
|
125
|
+
version_requirements: *id007
|
126
|
+
- !ruby/object:Gem::Dependency
|
127
|
+
name: ruby-debug19
|
128
|
+
prerelease: false
|
129
|
+
requirement: &id008 !ruby/object:Gem::Requirement
|
130
|
+
none: false
|
131
|
+
requirements:
|
132
|
+
- - ~>
|
133
|
+
- !ruby/object:Gem::Version
|
134
|
+
segments:
|
135
|
+
- 0
|
136
|
+
- 11
|
137
|
+
- 0
|
138
|
+
version: 0.11.0
|
139
|
+
type: :development
|
140
|
+
version_requirements: *id008
|
141
|
+
description: Matic adds attribute accessors and dirty tracking to Mongomatic and optionally shortens field names saved to MongoDB.
|
112
142
|
email:
|
113
143
|
- code@papercavalier.com
|
114
144
|
executables: []
|
@@ -126,6 +156,8 @@ files:
|
|
126
156
|
- Gemfile.lock
|
127
157
|
- README.md
|
128
158
|
- Rakefile
|
159
|
+
- benchmarks/create_many_books.rb
|
160
|
+
- le_fou.jpg
|
129
161
|
- lib/matic.rb
|
130
162
|
- lib/matic/version.rb
|
131
163
|
- matic.gemspec
|
@@ -133,6 +165,7 @@ files:
|
|
133
165
|
- spec/models/book.rb
|
134
166
|
- spec/models/person.rb
|
135
167
|
- spec/spec_helper.rb
|
168
|
+
- spec/support/faker.rb
|
136
169
|
- spec/support/mongomatic.rb
|
137
170
|
- spec_rubies
|
138
171
|
has_rdoc: true
|
@@ -166,10 +199,11 @@ rubyforge_project: matic
|
|
166
199
|
rubygems_version: 1.3.7
|
167
200
|
signing_key:
|
168
201
|
specification_version: 3
|
169
|
-
summary:
|
202
|
+
summary: A dirtier Mongomatic
|
170
203
|
test_files:
|
171
204
|
- spec/matic_spec.rb
|
172
205
|
- spec/models/book.rb
|
173
206
|
- spec/models/person.rb
|
174
207
|
- spec/spec_helper.rb
|
208
|
+
- spec/support/faker.rb
|
175
209
|
- spec/support/mongomatic.rb
|