phlexi-field 0.0.5 → 0.0.6

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: a2ff865f069b2361127071190b6f17cd58a553d9eadcb3084acce2e3cefbe6df
4
- data.tar.gz: 6af6e7c11737780a668ea39f86a6436540afa31e2f76a14d0201177e336ff649
3
+ metadata.gz: 5a93196112cf2988e3893ae65133271d65cfe8a3c118c274dd7170bd30735a67
4
+ data.tar.gz: 9f8c007cbbe91c52d856485a30ad0db0f72a5d687e62c2202a4c1e6703a5bfd9
5
5
  SHA512:
6
- metadata.gz: 617357cb149cc34431f4615ecc041207565a00e3855400fe804bd18c162af9c4e7b182a49d73c8d01deb122a087969531883316e3b1571595d72a7dbab56e84e
7
- data.tar.gz: afbfa1cefd2b4a31898e9aa90636f642395fc4d33d57b58989d3aaa8977232ce9d4d1b91602f1f63b4375854f2961de82935b88a5b11c5291fe90a0b55336907
6
+ metadata.gz: 1937ee5a4b0d478a67a38b0d098e305ffcafb27556957dfca8bcc1b827688feabfc29fffd0bb7f91159b0519b017cb4da8fa2bb3e62c3651f53d5cf58ef6ca76
7
+ data.tar.gz: 1b43ffa71ec09cf7a8c959b564485ed9d0486e031a4627c7c12f4b611d063ec19115128e9210e3e43981a887e71d11544169cd24395b793d990c13b0856329a2
@@ -67,7 +67,7 @@ module Phlexi
67
67
  end
68
68
 
69
69
  def determine_value_from_object
70
- object.respond_to?(key) ? object.public_send(key) : nil
70
+ Phlexi::Field::Support::Value.from(object, key)
71
71
  end
72
72
  end
73
73
  end
@@ -46,17 +46,9 @@ module Phlexi
46
46
  return custom_type.type if custom_type&.type
47
47
  end
48
48
 
49
- # Check if object responds to the key
50
- if object.respond_to?(key)
51
- # Fallback to inferring type from the value
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) ? root.dom_id : root.key
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
- id = if object.nil?
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, id].compact.join("_").underscore
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
- return @object.send(key) if @object.respond_to?(key)
111
- @object[key] if @object.is_a?(Hash)
105
+ Phlexi::Field::Support::Value.from(@object, key)
112
106
  end
113
107
 
114
108
  private
@@ -20,7 +20,7 @@ module Phlexi
20
20
  end
21
21
 
22
22
  def inspect
23
- "<#{self.class.name} key=#{key.inspect} parent=#{parent.inspect} />"
23
+ "<#{self.class.name} key=#{key.inspect} object=#{object.inspect} parent=#{parent.inspect} />"
24
24
  end
25
25
  end
26
26
  end
@@ -0,0 +1,12 @@
1
+ module Phlexi
2
+ module Field
3
+ module Support
4
+ module Value
5
+ def self.from(object, key)
6
+ return object[key] if object.is_a?(Hash)
7
+ object.public_send(key) if object.respond_to?(key)
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Phlexi
4
4
  module Field
5
- VERSION = "0.0.5"
5
+ VERSION = "0.0.6"
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.5
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-18 00:00:00.000000000 Z
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