smart_model 0.1.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT-LICENSE +2 -1
- data/lib/smart_model.rb +18 -6
- metadata +4 -4
data/MIT-LICENSE
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
Copyright (c) 2010
|
1
|
+
Copyright (c) 2010 Nathan Proença
|
2
2
|
|
3
3
|
Permission is hereby granted, free of charge, to any person obtaining
|
4
4
|
a copy of this software and associated documentation files (the
|
@@ -18,3 +18,4 @@ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
18
18
|
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
19
|
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
20
|
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
|
+
|
data/lib/smart_model.rb
CHANGED
@@ -2,11 +2,9 @@ require 'rubygems'
|
|
2
2
|
require 'mongo_mapper'
|
3
3
|
|
4
4
|
module SmartModel
|
5
|
-
module
|
5
|
+
module Attributes
|
6
6
|
def self.included(model)
|
7
|
-
|
8
|
-
model.send :include, MongoMapper::Document
|
9
|
-
# create database columns methods
|
7
|
+
model.send :include , MongoMapper::Document
|
10
8
|
%w(String Integer Boolean Array ObjectId Date Time).each do |name|
|
11
9
|
model.class_eval "
|
12
10
|
private
|
@@ -21,13 +19,27 @@ module SmartModel
|
|
21
19
|
end
|
22
20
|
"
|
23
21
|
end
|
24
|
-
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
module Relationships
|
26
|
+
def self.included(model)
|
27
|
+
model.send :include , MongoMapper::Document
|
25
28
|
model.class_eval "
|
26
29
|
def self.belongs_to(value)
|
27
|
-
key \"\#{value}_id\"
|
30
|
+
key \"\#{value}_id\" , ObjectId
|
28
31
|
super value
|
29
32
|
end"
|
30
33
|
end
|
31
34
|
end
|
35
|
+
|
36
|
+
module Base
|
37
|
+
def self.included(model)
|
38
|
+
# include MongoMapper::Document
|
39
|
+
model.send :include , MongoMapper::Document
|
40
|
+
model.send :include , SmartModel::Attributes
|
41
|
+
model.send :include , SmartModel::Relationships
|
42
|
+
end
|
43
|
+
end
|
32
44
|
end
|
33
45
|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: smart_model
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
8
|
+
- 3
|
9
9
|
- 0
|
10
|
-
version: 0.
|
10
|
+
version: 0.3.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- "Nathan Proen\xC3\xA7a"
|
@@ -26,7 +26,7 @@ dependencies:
|
|
26
26
|
requirements:
|
27
27
|
- - ">="
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
hash:
|
29
|
+
hash: 996871346
|
30
30
|
segments:
|
31
31
|
- 3
|
32
32
|
- 0
|