phlexi-field 0.0.7 → 0.0.8

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: b81988b45868d71c491619e29435eeae401a9ce46d7e1f2e646d5fd2a0adc8af
4
- data.tar.gz: 63c2472d49cb30609fabf6190c26e25801de083b9fece0918aac83bf761cb840
3
+ metadata.gz: 718d6322b8dd57d2ded2366a0d00ae5191305e98c178459a45660f9badcc73c6
4
+ data.tar.gz: cc8e6173c724aa41c00b102342d73b47029c6915d2226b3f0849a3262e929072
5
5
  SHA512:
6
- metadata.gz: 43654f76cfb84a8625b19a6147aa2bbb9bec4e01431be33f7ac6a27c9d288622d92a529214500ff412e08cb692e060d46443447d3066a7238a1a26a03a662052
7
- data.tar.gz: 9ace64b95a34ebb011ed0bb2b273238f1e33f58373a90bf0bd5bfbc62068fcc86c6fba722bebe2323be25b2bc8a73915ad1153da772f7c9ebf7bb73cc5d4f75b
6
+ metadata.gz: '0962dfaf9ffce3f6319becd919e3ceda58be30922341cf363803e0dec24a528bea3fa5526be4adb2a696e2f1a3cddc1d2824a1041dd17aa0232d33145761d413'
7
+ data.tar.gz: c1c1783cba57aa86d069e40e7637771d512fb3a04ccb0df19e6b1b8bb84b3287c58ae7cb3d66f7b0ac914e43bba27b659429c99db7c8f7113ad60120a1d39860
@@ -31,8 +31,8 @@ module Phlexi
31
31
  yield self if block_given?
32
32
  end
33
33
 
34
- def field(key, **attributes)
35
- create_child(key, attributes.delete(:builder_klass) || builder_klass, object: object, **attributes).tap do |field|
34
+ def field(key, template: false, **attributes)
35
+ create_child(key, attributes.delete(:builder_klass) || builder_klass, object: object, template:, **attributes).tap do |field|
36
36
  yield field if block_given?
37
37
  end
38
38
  end
@@ -51,10 +51,10 @@ module Phlexi
51
51
  # end
52
52
  # end
53
53
  # ```
54
- def nest_one(key, object: nil, as: nil, &)
54
+ def nest_one(key, object: nil, as: nil, template: false, &)
55
55
  object ||= object_value_for(key: key)
56
56
  key = as || key
57
- create_child(key, self.class, object:, builder_klass:, &)
57
+ create_child(key, self.class, object:, template:, builder_klass:, &)
58
58
  end
59
59
 
60
60
  # Wraps an array of objects in Namespace classes. For example, if `User#addresses` returns
@@ -73,10 +73,10 @@ module Phlexi
73
73
  # ```
74
74
  # The object within the block is a `Namespace` object that maps each object within the enumerable
75
75
  # to another `Namespace` or `Field`.
76
- def nest_many(key, collection: nil, as: nil, &)
76
+ def nest_many(key, collection: nil, as: nil, template: false, &)
77
77
  collection ||= Array(object_value_for(key: key))
78
78
  key = as || key
79
- create_child(key, self.class::NamespaceCollection, collection:, &)
79
+ create_child(key, self.class::NamespaceCollection, collection:, template:, &)
80
80
  end
81
81
 
82
82
  # Iterates through the children of the current namespace, which could be `Namespace` or `Field`
@@ -111,8 +111,12 @@ module Phlexi
111
111
 
112
112
  # Checks if the child exists. If it does then it returns that. If it doesn't, it will
113
113
  # build the child.
114
- def create_child(key, child_class, **kwargs, &block)
115
- @children.fetch(key) { @children[key] = child_class.new(key, parent: self, **kwargs, &block) }
114
+ def create_child(key, child_class, template: false, **, &)
115
+ if template
116
+ child_class.new(key, parent: self, **, &)
117
+ else
118
+ @children.fetch(key) { @children[key] = child_class.new(key, parent: self, **, &) }
119
+ end
116
120
  end
117
121
  end
118
122
  end
@@ -16,6 +16,10 @@ module Phlexi
16
16
  each(&block)
17
17
  end
18
18
 
19
+ def object
20
+ @collection
21
+ end
22
+
19
23
  private
20
24
 
21
25
  def each(&)
@@ -26,8 +30,15 @@ module Phlexi
26
30
  #
27
31
  # @return [Array<Namespace>] An array of namespace objects.
28
32
  def namespaces
29
- @namespaces ||= @collection.map.with_index do |object, key|
30
- build_namespace(key, object: object)
33
+ @namespaces ||= case @collection
34
+ when Hash
35
+ @collection.map do |key, object|
36
+ build_namespace(key, object: object)
37
+ end
38
+ when Array
39
+ @collection.map.with_index do |object, key|
40
+ build_namespace(key, object: object)
41
+ end
31
42
  end
32
43
  end
33
44
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Phlexi
4
4
  module Field
5
- VERSION = "0.0.7"
5
+ VERSION = "0.0.8"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: phlexi-field
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stefan Froelich
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-11-03 00:00:00.000000000 Z
11
+ date: 2024-11-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: phlex