phlexi-field 0.0.5 → 0.0.6
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 +5 -11
- 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: 5a93196112cf2988e3893ae65133271d65cfe8a3c118c274dd7170bd30735a67
|
4
|
+
data.tar.gz: 9f8c007cbbe91c52d856485a30ad0db0f72a5d687e62c2202a4c1e6703a5bfd9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1937ee5a4b0d478a67a38b0d098e305ffcafb27556957dfca8bcc1b827688feabfc29fffd0bb7f91159b0519b017cb4da8fa2bb3e62c3651f53d5cf58ef6ca76
|
7
|
+
data.tar.gz: 1b43ffa71ec09cf7a8c959b564485ed9d0486e031a4627c7c12f4b611d063ec19115128e9210e3e43981a887e71d11544169cd24395b793d990c13b0856329a2
|
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
|
@@ -84,12 +85,12 @@ module Phlexi
|
|
84
85
|
|
85
86
|
def dom_id
|
86
87
|
@dom_id ||= begin
|
87
|
-
|
88
|
+
object_id = if object.nil?
|
88
89
|
nil
|
89
90
|
elsif (primary_key = Phlexi::Field.object_primary_key(object))
|
90
91
|
primary_key&.to_s || :new
|
91
92
|
end
|
92
|
-
[key,
|
93
|
+
[key, object_id].compact.join("_").underscore
|
93
94
|
end
|
94
95
|
end
|
95
96
|
|
@@ -100,15 +101,8 @@ module Phlexi
|
|
100
101
|
|
101
102
|
protected
|
102
103
|
|
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
104
|
def object_value_for(key:)
|
110
|
-
|
111
|
-
@object[key] if @object.is_a?(Hash)
|
105
|
+
Phlexi::Field::Support::Value.from(@object, key)
|
112
106
|
end
|
113
107
|
|
114
108
|
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.6
|
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-10-
|
11
|
+
date: 2024-10-25 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
|