phlexi-field 0.0.5 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/phlexi/field/builder.rb +1 -1
- data/lib/phlexi/field/options/inferred_types.rb +3 -11
- data/lib/phlexi/field/structure/dom.rb +5 -1
- data/lib/phlexi/field/structure/namespace.rb +9 -13
- data/lib/phlexi/field/structure/node.rb +1 -1
- data/lib/phlexi/field/support/value.rb +12 -0
- data/lib/phlexi/field/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b81988b45868d71c491619e29435eeae401a9ce46d7e1f2e646d5fd2a0adc8af
|
4
|
+
data.tar.gz: 63c2472d49cb30609fabf6190c26e25801de083b9fece0918aac83bf761cb840
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 43654f76cfb84a8625b19a6147aa2bbb9bec4e01431be33f7ac6a27c9d288622d92a529214500ff412e08cb692e060d46443447d3066a7238a1a26a03a662052
|
7
|
+
data.tar.gz: 9ace64b95a34ebb011ed0bb2b273238f1e33f58373a90bf0bd5bfbc62068fcc86c6fba722bebe2323be25b2bc8a73915ad1153da772f7c9ebf7bb73cc5d4f75b
|
data/lib/phlexi/field/builder.rb
CHANGED
@@ -46,17 +46,9 @@ module Phlexi
|
|
46
46
|
return custom_type.type if custom_type&.type
|
47
47
|
end
|
48
48
|
|
49
|
-
#
|
50
|
-
|
51
|
-
|
52
|
-
return infer_field_type_from_value(object.send(key))
|
53
|
-
end
|
54
|
-
|
55
|
-
# Check if object is a has that contains key
|
56
|
-
if object.respond_to?(:fetch)
|
57
|
-
# Fallback to inferring type from the value
|
58
|
-
return infer_field_type_from_value(object[key])
|
59
|
-
end
|
49
|
+
# Fallback to inferring type from the value
|
50
|
+
value = Phlexi::Field::Support::Value.from(object, key)
|
51
|
+
return infer_field_type_from_value(value) unless value.nil?
|
60
52
|
|
61
53
|
# Default to string if we can't determine the type
|
62
54
|
:string
|
@@ -22,7 +22,11 @@ module Phlexi
|
|
22
22
|
def id
|
23
23
|
@id ||= begin
|
24
24
|
root, *rest = lineage
|
25
|
-
root_key = root.respond_to?(:dom_id)
|
25
|
+
root_key = if root.respond_to?(:dom_id)
|
26
|
+
root.dom_id
|
27
|
+
else
|
28
|
+
root.key
|
29
|
+
end
|
26
30
|
rest.map(&:key).unshift(root_key).join("_")
|
27
31
|
end
|
28
32
|
end
|
@@ -22,10 +22,11 @@ module Phlexi
|
|
22
22
|
|
23
23
|
attr_reader :builder_klass, :object
|
24
24
|
|
25
|
-
def initialize(key, parent:, builder_klass:, object: nil)
|
25
|
+
def initialize(key, parent:, builder_klass:, object: nil, dom_id: nil)
|
26
26
|
super(key, parent: parent)
|
27
27
|
@builder_klass = builder_klass
|
28
28
|
@object = object
|
29
|
+
@dom_id = dom_id
|
29
30
|
@children = {}
|
30
31
|
yield self if block_given?
|
31
32
|
end
|
@@ -50,8 +51,9 @@ module Phlexi
|
|
50
51
|
# end
|
51
52
|
# end
|
52
53
|
# ```
|
53
|
-
def nest_one(key, object: nil, &)
|
54
|
+
def nest_one(key, object: nil, as: nil, &)
|
54
55
|
object ||= object_value_for(key: key)
|
56
|
+
key = as || key
|
55
57
|
create_child(key, self.class, object:, builder_klass:, &)
|
56
58
|
end
|
57
59
|
|
@@ -71,8 +73,9 @@ module Phlexi
|
|
71
73
|
# ```
|
72
74
|
# The object within the block is a `Namespace` object that maps each object within the enumerable
|
73
75
|
# to another `Namespace` or `Field`.
|
74
|
-
def nest_many(key, collection: nil, &)
|
76
|
+
def nest_many(key, collection: nil, as: nil, &)
|
75
77
|
collection ||= Array(object_value_for(key: key))
|
78
|
+
key = as || key
|
76
79
|
create_child(key, self.class::NamespaceCollection, collection:, &)
|
77
80
|
end
|
78
81
|
|
@@ -84,12 +87,12 @@ module Phlexi
|
|
84
87
|
|
85
88
|
def dom_id
|
86
89
|
@dom_id ||= begin
|
87
|
-
|
90
|
+
object_id = if object.nil?
|
88
91
|
nil
|
89
92
|
elsif (primary_key = Phlexi::Field.object_primary_key(object))
|
90
93
|
primary_key&.to_s || :new
|
91
94
|
end
|
92
|
-
[key,
|
95
|
+
[key, object_id].compact.join("_").underscore
|
93
96
|
end
|
94
97
|
end
|
95
98
|
|
@@ -100,15 +103,8 @@ module Phlexi
|
|
100
103
|
|
101
104
|
protected
|
102
105
|
|
103
|
-
# Calls the corresponding method on the object for the `key` name, if it exists. For example
|
104
|
-
# if the `key` is `email` on `User`, this method would call `User#email` if the method is
|
105
|
-
# present.
|
106
|
-
#
|
107
|
-
# This method could be overwritten if the mapping between the `@object` and `key` name is not
|
108
|
-
# a method call. For example, a `Hash` would be accessed via `user[:email]` instead of `user.send(:email)`
|
109
106
|
def object_value_for(key:)
|
110
|
-
|
111
|
-
@object[key] if @object.is_a?(Hash)
|
107
|
+
Phlexi::Field::Support::Value.from(@object, key)
|
112
108
|
end
|
113
109
|
|
114
110
|
private
|
data/lib/phlexi/field/version.rb
CHANGED
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.
|
4
|
+
version: 0.0.7
|
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
|
+
date: 2024-11-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: phlex
|
@@ -216,6 +216,7 @@ files:
|
|
216
216
|
- lib/phlexi/field/structure/namespace.rb
|
217
217
|
- lib/phlexi/field/structure/namespace_collection.rb
|
218
218
|
- lib/phlexi/field/structure/node.rb
|
219
|
+
- lib/phlexi/field/support/value.rb
|
219
220
|
- lib/phlexi/field/theme.rb
|
220
221
|
- lib/phlexi/field/version.rb
|
221
222
|
- sig/phlexi/field.rbs
|