worsemodel 0.1.9 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/supermodel/association.rb +16 -7
- data/supermodel.gemspec +1 -1
- metadata +2 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b49bf11cdc17481d4ac8ea46a85503e5f285ced7
|
4
|
+
data.tar.gz: cd324e945b722ab330e247395e32edbb003e4438
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5fcec7a9d06626dd306cb206ee5a285897e029e808d2304f6436b03ebf164a51be041519f08973047566e79fd334b22ccf41d4a89f9467d41782fe6112c8b703
|
7
|
+
data.tar.gz: 6aa19ec5c2b02d9d5f2f61444897a2fd356a5bb456c0cd42f518fb6dc8ae46f7016f63606b052c8faa68ee0de6abc414a8009de273d08e313c17763b1012342d
|
@@ -8,29 +8,38 @@ module SuperModel
|
|
8
8
|
class_name = options[:class_name] || to_model.classify
|
9
9
|
foreign_key = options[:foreign_key] || "#{to_model}_id"
|
10
10
|
primary_key = options[:primary_key] || "id"
|
11
|
-
|
11
|
+
|
12
12
|
attributes foreign_key
|
13
|
-
|
13
|
+
|
14
14
|
class_eval(<<-EOS, __FILE__, __LINE__ + 1)
|
15
15
|
def #{to_model} # def user
|
16
16
|
#{foreign_key} && #{class_name}.find(#{foreign_key}) # user_id && User.find(user_id)
|
17
17
|
end # end
|
18
|
-
#
|
18
|
+
#
|
19
19
|
def #{to_model}? # def user?
|
20
20
|
#{foreign_key} && #{class_name}.exists?(#{foreign_key}) # user_id && User.exists?(user_id)
|
21
21
|
end # end
|
22
|
-
#
|
22
|
+
#
|
23
23
|
def #{to_model}=(object) # def user=(model)
|
24
24
|
self.#{foreign_key} = (object && object.#{primary_key}) # self.user_id = (model && model.id)
|
25
25
|
end # end
|
26
26
|
EOS
|
27
27
|
end
|
28
|
-
|
28
|
+
|
29
29
|
def has_many(to_model, options = {})
|
30
30
|
to_model = to_model.to_s
|
31
31
|
class_name = options[:class_name] || to_model.classify
|
32
32
|
foreign_key = options[:foreign_key] || "#{model_name.singular}_id"
|
33
33
|
primary_key = options[:primary_key] || "id"
|
34
|
+
|
35
|
+
if (dependent = options[:dependent])
|
36
|
+
class_eval(<<-EOS, __FILE__, __LINE__ + 1)
|
37
|
+
before_#{dependent} do
|
38
|
+
#{to_model}.each(&:#{dependent}) # has_many :objects, dependent: :destroy
|
39
|
+
end
|
40
|
+
EOS
|
41
|
+
end
|
42
|
+
|
34
43
|
class_eval(<<-EOS, __FILE__, __LINE__ + 1)
|
35
44
|
def #{to_model} # def user
|
36
45
|
#{class_name}.find_all_by_attribute( # User.find_all_by_attribute(
|
@@ -41,11 +50,11 @@ module SuperModel
|
|
41
50
|
EOS
|
42
51
|
end
|
43
52
|
end
|
44
|
-
|
53
|
+
|
45
54
|
module Model
|
46
55
|
def self.included(base)
|
47
56
|
base.extend(ClassMethods)
|
48
57
|
end
|
49
58
|
end
|
50
59
|
end
|
51
|
-
end
|
60
|
+
end
|
data/supermodel.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: worsemodel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alex MacCaw
|
@@ -85,9 +85,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
85
85
|
version: '0'
|
86
86
|
requirements: []
|
87
87
|
rubyforge_project:
|
88
|
-
rubygems_version: 2.
|
88
|
+
rubygems_version: 2.5.1
|
89
89
|
signing_key:
|
90
90
|
specification_version: 4
|
91
91
|
summary: In memory DB using ActiveModel
|
92
92
|
test_files: []
|
93
|
-
has_rdoc:
|