matic 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +2 -2
- data/lib/matic.rb +28 -30
- data/lib/matic/version.rb +1 -1
- data/matic.gemspec +3 -1
- metadata +2 -11
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
matic (0.1.
|
4
|
+
matic (0.1.1)
|
5
5
|
activemodel (~> 3.0.0)
|
6
6
|
activesupport (~> 3.0.0)
|
7
7
|
mongomatic (~> 0.6.0)
|
@@ -21,7 +21,7 @@ GEM
|
|
21
21
|
i18n (0.4.2)
|
22
22
|
mongo (1.1.2)
|
23
23
|
bson (>= 1.1.1)
|
24
|
-
mongomatic (0.6.
|
24
|
+
mongomatic (0.6.2)
|
25
25
|
activesupport (>= 2.3.5)
|
26
26
|
bson (~> 1.1)
|
27
27
|
mongo (~> 1.1)
|
data/lib/matic.rb
CHANGED
@@ -10,44 +10,38 @@ module Matic
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def field(attr_name)
|
13
|
-
|
14
|
-
attribute_method_matchers.each do |matcher|
|
15
|
-
unless instance_method_already_implemented?(matcher.method_name(attr_name))
|
16
|
-
generate_method = "define_method_#{matcher.prefix}attribute#{matcher.suffix}"
|
17
|
-
|
18
|
-
if respond_to?(generate_method)
|
19
|
-
send(generate_method, attr_name)
|
20
|
-
else
|
21
|
-
method_name = matcher.method_name(attr_name)
|
22
|
-
|
23
|
-
generated_attribute_methods.module_eval <<-STR, __FILE__, __LINE__ + 1
|
24
|
-
if method_defined?(:#{method_name})
|
25
|
-
undef :#{method_name}
|
26
|
-
end
|
27
|
-
def #{method_name}(*args)
|
28
|
-
send(:#{matcher.method_missing_target}, '#{attr_name}', *args)
|
29
|
-
end
|
30
|
-
STR
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
13
|
+
generate_attribute_methods(attr_name)
|
34
14
|
|
35
15
|
define_method(attr_name) do
|
36
16
|
self[attr_name.to_s]
|
37
17
|
end
|
38
18
|
|
39
19
|
define_method("#{attr_name}=") do |val|
|
40
|
-
|
20
|
+
unless val == self[attr_name.to_s]
|
21
|
+
eval("#{attr_name}_will_change!")
|
22
|
+
end
|
23
|
+
|
41
24
|
self[attr_name.to_s] = val
|
42
25
|
end
|
43
26
|
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def generate_attribute_methods(attr_name)
|
31
|
+
attribute_method_matchers.each do |matcher|
|
32
|
+
method_name = matcher.method_name(attr_name)
|
33
|
+
|
34
|
+
generated_attribute_methods.module_eval <<-STR, __FILE__, __LINE__ + 1
|
35
|
+
def #{method_name}(*args)
|
36
|
+
send(:#{matcher.method_missing_target}, '#{attr_name}', *args)
|
37
|
+
end
|
38
|
+
STR
|
39
|
+
end
|
40
|
+
end
|
44
41
|
end
|
45
42
|
|
46
43
|
def insert(opts={})
|
47
|
-
if super
|
48
|
-
@previously_changed = changes
|
49
|
-
@changed_attributes.clear
|
50
|
-
end
|
44
|
+
clear_changes if super
|
51
45
|
end
|
52
46
|
|
53
47
|
def insert!(opts={})
|
@@ -55,10 +49,7 @@ module Matic
|
|
55
49
|
end
|
56
50
|
|
57
51
|
def update(opts={}, update_doc=@doc)
|
58
|
-
if super
|
59
|
-
@previously_changed = changes
|
60
|
-
@changed_attributes.clear
|
61
|
-
end
|
52
|
+
clear_changes if super
|
62
53
|
end
|
63
54
|
|
64
55
|
def update!(opts={}, update_doc=@doc)
|
@@ -68,4 +59,11 @@ module Matic
|
|
68
59
|
def save
|
69
60
|
is_new ? insert : update
|
70
61
|
end
|
62
|
+
|
63
|
+
private
|
64
|
+
|
65
|
+
def clear_changes
|
66
|
+
@previously_changed = changes
|
67
|
+
@changed_attributes.clear
|
68
|
+
end
|
71
69
|
end
|
data/lib/matic/version.rb
CHANGED
data/matic.gemspec
CHANGED
@@ -25,5 +25,7 @@ Gem::Specification.new do |s|
|
|
25
25
|
s.add_development_dependency("bson_ext", "~> 1.1.0")
|
26
26
|
s.add_development_dependency("rake", "~> 0.8.7")
|
27
27
|
s.add_development_dependency("rspec", "~> 2.0.0")
|
28
|
-
|
28
|
+
if RUBY_PLATFORM.include?("1.9")
|
29
|
+
s.add_development_dependency("ruby-debug19", "~> 0.11.0")
|
30
|
+
end
|
29
31
|
end
|
metadata
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: matic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash: 27
|
5
4
|
prerelease: false
|
6
5
|
segments:
|
7
6
|
- 0
|
8
7
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
8
|
+
- 1
|
9
|
+
version: 0.1.1
|
11
10
|
platform: ruby
|
12
11
|
authors:
|
13
12
|
- Hakan Ensari
|
@@ -27,7 +26,6 @@ dependencies:
|
|
27
26
|
requirements:
|
28
27
|
- - ~>
|
29
28
|
- !ruby/object:Gem::Version
|
30
|
-
hash: 7
|
31
29
|
segments:
|
32
30
|
- 0
|
33
31
|
- 6
|
@@ -43,7 +41,6 @@ dependencies:
|
|
43
41
|
requirements:
|
44
42
|
- - ~>
|
45
43
|
- !ruby/object:Gem::Version
|
46
|
-
hash: 7
|
47
44
|
segments:
|
48
45
|
- 3
|
49
46
|
- 0
|
@@ -59,7 +56,6 @@ dependencies:
|
|
59
56
|
requirements:
|
60
57
|
- - ~>
|
61
58
|
- !ruby/object:Gem::Version
|
62
|
-
hash: 7
|
63
59
|
segments:
|
64
60
|
- 3
|
65
61
|
- 0
|
@@ -75,7 +71,6 @@ dependencies:
|
|
75
71
|
requirements:
|
76
72
|
- - ~>
|
77
73
|
- !ruby/object:Gem::Version
|
78
|
-
hash: 19
|
79
74
|
segments:
|
80
75
|
- 1
|
81
76
|
- 1
|
@@ -91,7 +86,6 @@ dependencies:
|
|
91
86
|
requirements:
|
92
87
|
- - ~>
|
93
88
|
- !ruby/object:Gem::Version
|
94
|
-
hash: 49
|
95
89
|
segments:
|
96
90
|
- 0
|
97
91
|
- 8
|
@@ -107,7 +101,6 @@ dependencies:
|
|
107
101
|
requirements:
|
108
102
|
- - ~>
|
109
103
|
- !ruby/object:Gem::Version
|
110
|
-
hash: 15
|
111
104
|
segments:
|
112
105
|
- 2
|
113
106
|
- 0
|
@@ -155,7 +148,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
155
148
|
requirements:
|
156
149
|
- - ">="
|
157
150
|
- !ruby/object:Gem::Version
|
158
|
-
hash: 3
|
159
151
|
segments:
|
160
152
|
- 0
|
161
153
|
version: "0"
|
@@ -164,7 +156,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
164
156
|
requirements:
|
165
157
|
- - ">="
|
166
158
|
- !ruby/object:Gem::Version
|
167
|
-
hash: 3
|
168
159
|
segments:
|
169
160
|
- 0
|
170
161
|
version: "0"
|