Class: Plutonium::UI::Form::Concerns::RendersNestedResourceFields::NestedFieldContext Private

Inherits:
Object
  • Object
show all
Defined in:
lib/plutonium/ui/form/concerns/renders_nested_resource_fields.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, definition:, resource_class:, resource_definition:, object_class:, declared_options:) ⇒ NestedFieldContext

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of NestedFieldContext.

Parameters:

  • declared_options (Hash)

    the nested input's own options, already proc-resolved by the form (the context has no form to resolve against). Everything merged in below — nested-attribute macro, limits — is derived from the model, never authored, so this is the only half that can carry a proc.



31
32
33
34
35
36
37
38
39
40
# File 'lib/plutonium/ui/form/concerns/renders_nested_resource_fields.rb', line 31

def initialize(name:, definition:, resource_class:, resource_definition:, object_class:, declared_options:)
  @name = name
  @definition = definition
  @resource_definition = resource_definition
  @resource_class = resource_class
  @declared_options = declared_options
  @options = build_options
  @permitted_fields = build_permitted_fields
  @object_class = object_class
end

Instance Attribute Details

#definitionObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



24
25
26
# File 'lib/plutonium/ui/form/concerns/renders_nested_resource_fields.rb', line 24

def definition
  @definition
end

#nameObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



24
25
26
# File 'lib/plutonium/ui/form/concerns/renders_nested_resource_fields.rb', line 24

def name
  @name
end

#optionsObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



24
25
26
# File 'lib/plutonium/ui/form/concerns/renders_nested_resource_fields.rb', line 24

def options
  @options
end

#permitted_fieldsObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



24
25
26
# File 'lib/plutonium/ui/form/concerns/renders_nested_resource_fields.rb', line 24

def permitted_fields
  @permitted_fields
end

Instance Method Details

#blank_objectObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



54
55
56
# File 'lib/plutonium/ui/form/concerns/renders_nested_resource_fields.rb', line 54

def blank_object
  (@object_class || nested_attribute_options[:class])&.new
end

#nested_attribute_optionsObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



42
43
44
# File 'lib/plutonium/ui/form/concerns/renders_nested_resource_fields.rb', line 42

def nested_attribute_options
  @nested_attribute_options ||= @resource_class.all_nested_attributes_options[@name] || {}
end

#nested_fields_input_paramObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



46
47
48
# File 'lib/plutonium/ui/form/concerns/renders_nested_resource_fields.rb', line 46

def nested_fields_input_param
  @options[:as] || :"#{@name}_attributes"
end

#nested_fields_multiple?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


50
51
52
# File 'lib/plutonium/ui/form/concerns/renders_nested_resource_fields.rb', line 50

def nested_fields_multiple?
  @options[:multiple]
end