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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4cc38391b46ea4d3dd453708fd14842a0848017c270003e0ffcc67088aaf4ce8
4
- data.tar.gz: 91c862cc0a28c7f2be22d9af319e41eae764421cf8234badacc0dc66c708afa5
3
+ metadata.gz: 264e500907e70a06681bb42c4553d532b52f34b311145b993065725672ccdc54
4
+ data.tar.gz: ea8d279f54b93ca9f573f7350f63432f11dc26b3e4ad6eb4de7d87ce0b78cfd0
5
5
  SHA512:
6
- metadata.gz: c9a52467cb2e00a176b5044869b125728b45eca076931ecbc5f049ca72eccf1b33d878516449ef29dbbcc08501add7c59ed5eeedd191faadb9d594b571b01146
7
- data.tar.gz: 401e27c9bd4024c242eda7d211d2df1759cbea23a85a12c0375c59443490d4dec5edafd8159d4ea662fb8300935a2c09cf98c5f65e1ad6989eedd98220bc0632
6
+ metadata.gz: 92288f3451f81cadb980157da7783060aef7d071ea3d83a45646e1a02e8586ad3d58b03cc8bd49514de16e68fb7a20ca96c7b4756b2687a9ca4b7e24fad5cdf3
7
+ data.tar.gz: f98fa84485a428a4c1bf53ff45fd138dbaa77b8114872e77cfff480e28db4064bfbaeedd2e9d4c08086b39073733020d7fe32e3c052943503799fe8de56b0008
@@ -14,7 +14,7 @@ module Dsl
14
14
  # +key+:: the corresponding key in the params hash
15
15
  # +possible_types+:: A hash that follows the below format
16
16
  #
17
- # polymorph(:content, :program_id, {
17
+ # polymorph(:content, {
18
18
  # foo: Bar
19
19
  # })
20
20
  #
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
@@ -29,6 +29,7 @@ module Handlers
29
29
  })
30
30
 
31
31
  @form.new(@attributes, @resource.send(@relation)).save!
32
+ @resource.reload
32
33
  end
33
34
  end
34
35
  end
@@ -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
- polymorph_instance = form_class.new(@params_to_send, @resource.try(@polymorph[:key])).save!
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[:types][
44
- @resource.try("#{@polymorph[:key]}_type") || clean_params.try(:to_sym)
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.beta.2
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: 1.3.1
95
+ version: '0'
96
96
  requirements: []
97
97
  rubyforge_project:
98
98
  rubygems_version: 2.7.3