action_form 0.6.4 → 0.6.5

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
  SHA256:
3
- metadata.gz: 3e194888488e1747bdc4e384b5cfb2f6fd78ab9cbcf16c9bf00fd81fda9bb849
4
- data.tar.gz: bb3f84b823d7fc870fbd84fcfbbdf58259792345b47aba4ac9681fdd58d1c5e6
3
+ metadata.gz: 72382d4935502742cc4736c21c7964185e8fdb154972bc4ae38ae9497c18009d
4
+ data.tar.gz: a28f5cc2229551ce6a116721d8c34a4d134a2acc1bea9c1b081e633c20f60834
5
5
  SHA512:
6
- metadata.gz: 22dd6884375dd7eaa180de1210a8ab702a1aefaa9e72c4988bc00f3f5ec65db16c5018281fabfbc5bd770a355460aa077eca1d3b66766269ed13f2ab09d9d0dc
7
- data.tar.gz: 8216c17312f90892b83cae63291222d6630a7d5c33ea8b623e3785b1d68e0b7f82b56d8952164f1960762c5b40274639cbe2662ec792239c0395a091312b2ea7
6
+ metadata.gz: 6efb2e07f6de58b2d25af0e9dcaf3d0c779a7a72ea7d70acf0a840ceb70d74053902742b659369e99d7b723660e2bcac87784a9c17b1bfa3ad2f876d7e92d93b
7
+ data.tar.gz: 4fd0ede2b1ef5bc8a74f12ceefd75e4d5af245abe4a26cf60fa294320198904af6f2be66245beac5a96f45c7bb72f4f0409a2f352e6f068e0cdf3f558f338dd8
@@ -12,7 +12,7 @@ module ActionForm
12
12
  attr_reader :elements_instances, :scope, :object, :html_options, :errors
13
13
 
14
14
  class << self
15
- attr_writer :elements, :scope
15
+ attr_writer :elements, :scope, :params_definition
16
16
 
17
17
  def subform_class
18
18
  ActionForm::Subform
@@ -28,6 +28,8 @@ module ActionForm
28
28
  super
29
29
  subclass.elements = elements.dup
30
30
  subclass.scope = scope.dup
31
+ subclass.params_definition = Class.new(params_definition)
32
+ subclass.params_definition.form_class = subclass
31
33
  end
32
34
  end
33
35
 
@@ -35,7 +37,7 @@ module ActionForm
35
37
  super()
36
38
  @object = object
37
39
  @scope ||= scope
38
- @params = @scope && params.respond_to?(@scope) ? params.public_send(@scope) : params
40
+ @params = params
39
41
  @html_options = html_options
40
42
  @elements_instances = []
41
43
  @owner = owner
@@ -24,6 +24,7 @@ module ActionForm
24
24
 
25
25
  # TODO: add support for outputless elements
26
26
  def element(name, &block)
27
+ @params_definition = nil
27
28
  elements[name] = Class.new(ActionForm::Element)
28
29
  elements[name].class_eval(&block)
29
30
  define_singleton_method(:"#{name}_element") do |klass = nil, &block|
@@ -32,6 +33,7 @@ module ActionForm
32
33
  end
33
34
 
34
35
  def many(name, default: nil, &block)
36
+ @params_definition = nil
35
37
  subform_definition = Class.new(ActionForm::SubformsCollection)
36
38
  subform_definition.host_class = self
37
39
  subform_definition.class_eval(&block) if block
@@ -43,6 +45,7 @@ module ActionForm
43
45
  end
44
46
 
45
47
  def subform(name, default: nil, &block)
48
+ @params_definition = nil
46
49
  elements[name] = Class.new(subform_class)
47
50
  elements[name].class_eval(&block)
48
51
  elements[name].default = default if default
@@ -31,19 +31,6 @@ module ActionForm
31
31
  @scope = model.model_name.param_key.to_sym
32
32
  end
33
33
 
34
- def params_definition(scope: self.scope)
35
- return super unless scope
36
-
37
- @params_definitions ||= Hash.new do |h, key|
38
- h[key] = begin
39
- klass = super
40
- Class.new(params_class) { has scope, klass }
41
- end
42
- end
43
- @params_definitions[scope].form_class = self
44
- @params_definitions[scope]
45
- end
46
-
47
34
  def many(name, default: nil, &block)
48
35
  super
49
36
  elements[name].subform_definition.add_primary_key_element
@@ -13,13 +13,12 @@ module ActionForm
13
13
  ActionForm::Params
14
14
  end
15
15
 
16
- def params_definition(*)
16
+ def params_definition
17
17
  @params_definition ||= create_params_definition
18
18
  end
19
19
 
20
20
  def params(&block)
21
- @params_definition = scope ? params_definition(scope: scope) : create_params_definition(&block)
22
- @params_definition.class_eval(&block) if block
21
+ @params_definition = Class.new(params_definition, &block) if block
23
22
  end
24
23
 
25
24
  def create_params_definition # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActionForm
4
- VERSION = "0.6.4"
4
+ VERSION = "0.6.5"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: action_form
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.4
4
+ version: 0.6.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrii Baran