worsemodel 0.1.9 → 0.2.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1ce7f3751966028db5b242d65a3c15f81fc3e21d
4
- data.tar.gz: 747684787f00a309f9ffbd7de06afc2ff038c147
3
+ metadata.gz: b49bf11cdc17481d4ac8ea46a85503e5f285ced7
4
+ data.tar.gz: cd324e945b722ab330e247395e32edbb003e4438
5
5
  SHA512:
6
- metadata.gz: 5fb68b5801d1a246f064deb4f4dc3c522fb9b2890c41637de62b394c3a5e5d1e40870b3a849e71620279314bd4e396c752c1a59e2f48f71758d9766616a85796
7
- data.tar.gz: 630967abac0d6b6a5d6a890e2693e2c43f28a89ce4614bf3a525b522d5aa94a0f1018ccebd509a0cc04f69962f5977c1e83e5afd2346dee7547a64d498ad855d
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
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = 'worsemodel'
8
- s.version = '0.1.9'
8
+ s.version = '0.2.0'
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Alex MacCaw"]
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.1.9
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.4.5
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: