active_form_objects 1.0.0.beta.2 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/dsl/polymorphs.rb +1 -1
- data/lib/handlers/base.rb +9 -0
- data/lib/handlers/delegates.rb +1 -0
- data/lib/handlers/polymorphs.rb +10 -6
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 264e500907e70a06681bb42c4553d532b52f34b311145b993065725672ccdc54
|
4
|
+
data.tar.gz: ea8d279f54b93ca9f573f7350f63432f11dc26b3e4ad6eb4de7d87ce0b78cfd0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 92288f3451f81cadb980157da7783060aef7d071ea3d83a45646e1a02e8586ad3d58b03cc8bd49514de16e68fb7a20ca96c7b4756b2687a9ca4b7e24fad5cdf3
|
7
|
+
data.tar.gz: f98fa84485a428a4c1bf53ff45fd138dbaa77b8114872e77cfff480e28db4064bfbaeedd2e9d4c08086b39073733020d7fe32e3c052943503799fe8de56b0008
|
data/lib/dsl/polymorphs.rb
CHANGED
data/lib/handlers/base.rb
CHANGED
@@ -14,5 +14,14 @@ module Handlers
|
|
14
14
|
def upper(var)
|
15
15
|
@klass.class.class_variable_get(var)[@klass.class.name]
|
16
16
|
end
|
17
|
+
|
18
|
+
def raise_error(string)
|
19
|
+
raise ActiveFormObjects::Error.new("[#{@klass.class.name}] #{string}")
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
module ActiveFormObjects
|
25
|
+
class Error < RuntimeError
|
17
26
|
end
|
18
27
|
end
|
data/lib/handlers/delegates.rb
CHANGED
data/lib/handlers/polymorphs.rb
CHANGED
@@ -28,25 +28,29 @@ module Handlers
|
|
28
28
|
#
|
29
29
|
def initialize(klass, polymorph)
|
30
30
|
@polymorph = polymorph
|
31
|
+
|
31
32
|
super(klass)
|
32
33
|
end
|
33
34
|
|
34
35
|
def handle
|
35
36
|
@params_to_send = @params[@polymorph[:key]] || {}
|
36
|
-
|
37
|
+
form = form_class
|
38
|
+
|
39
|
+
raise_error("The form resolved with key '#{@type}' seems to be nil. Check your polymorphic relation key and the associated forms.") if form.nil?
|
40
|
+
|
41
|
+
polymorph_instance = form.new(@params_to_send, @resource.try(@polymorph[:key])).save!
|
42
|
+
|
37
43
|
@params["#{@polymorph[:key]}_id"] = polymorph_instance.id
|
38
44
|
@params["#{@polymorph[:key]}_type"] = polymorph_instance.class.name
|
39
45
|
@params.delete(@polymorph[:key])
|
40
46
|
end
|
41
47
|
|
42
48
|
def form_class
|
43
|
-
@polymorph[:
|
44
|
-
|
45
|
-
]
|
46
|
-
end
|
49
|
+
@type = @resource.try(@polymorph[:key]).try(:type) || @params_to_send['type']
|
50
|
+
raise_error("No 'type' method or 'type‘ key found in params for '#{@polymorph[:key]}' polymorphic relation") if @type.nil?
|
47
51
|
|
48
|
-
def clean_params
|
49
52
|
@params_to_send.delete(:type)
|
53
|
+
@polymorph[:types][@type.try(:to_sym)]
|
50
54
|
end
|
51
55
|
end
|
52
56
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_form_objects
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.0
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michaël Villeneuve
|
@@ -90,9 +90,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
90
90
|
version: '0'
|
91
91
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
92
92
|
requirements:
|
93
|
-
- - "
|
93
|
+
- - ">="
|
94
94
|
- !ruby/object:Gem::Version
|
95
|
-
version:
|
95
|
+
version: '0'
|
96
96
|
requirements: []
|
97
97
|
rubyforge_project:
|
98
98
|
rubygems_version: 2.7.3
|