lib/phlexi/field/structure/namespace.rb in phlexi-field-0.0.6 vs lib/phlexi/field/structure/namespace.rb in phlexi-field-0.0.7
- old
+ new
@@ -49,12 +49,13 @@
# nest_one :profile do |profile|
# render profile.field(:gender).input_tag
# end
# end
# ```
- def nest_one(key, object: nil, &)
+ def nest_one(key, object: nil, as: nil, &)
object ||= object_value_for(key: key)
+ key = as || key
create_child(key, self.class, object:, builder_klass:, &)
end
# Wraps an array of objects in Namespace classes. For example, if `User#addresses` returns
# an enumerable or array of `Address` classes:
@@ -70,11 +71,12 @@
# end
# end
# ```
# The object within the block is a `Namespace` object that maps each object within the enumerable
# to another `Namespace` or `Field`.
- def nest_many(key, collection: nil, &)
+ def nest_many(key, collection: nil, as: nil, &)
collection ||= Array(object_value_for(key: key))
+ key = as || key
create_child(key, self.class::NamespaceCollection, collection:, &)
end
# Iterates through the children of the current namespace, which could be `Namespace` or `Field`
# objects.