Class: Super::Form::SchemaTypes::Generic
- Inherits:
-
Object
- Object
- Super::Form::SchemaTypes::Generic
- Defined in:
- lib/super/form/schema_types.rb
Instance Attribute Summary collapse
-
#nested_fields ⇒ Object
readonly
Returns the value of attribute nested_fields.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #[](key) ⇒ Object
- #each_attribute ⇒ Object
-
#initialize(partial_path:, extras:, nested:) ⇒ Generic
constructor
A new instance of Generic.
- #label ⇒ Object
- #reader ⇒ Object
-
#to_partial_path ⇒ String
This takes advantage of a feature of Rails.
Constructor Details
#initialize(partial_path:, extras:, nested:) ⇒ Generic
Returns a new instance of Generic.
7 8 9 10 11 |
# File 'lib/super/form/schema_types.rb', line 7 def initialize(partial_path:, extras:, nested:) @partial_path = partial_path @extras = extras @nested_fields = nested end |
Instance Attribute Details
#nested_fields ⇒ Object (readonly)
Returns the value of attribute nested_fields.
13 14 15 |
# File 'lib/super/form/schema_types.rb', line 13 def nested_fields @nested_fields end |
Instance Method Details
#==(other) ⇒ Object
53 54 55 56 57 58 59 60 |
# File 'lib/super/form/schema_types.rb', line 53 def ==(other) return false if other.class != self.class return false if other.instance_variable_get(:@partial_path) != @partial_path return false if other.instance_variable_get(:@extras) != @extras return false if other.instance_variable_get(:@nested_fields) != @nested_fields true end |
#[](key) ⇒ Object
35 36 37 |
# File 'lib/super/form/schema_types.rb', line 35 def [](key) @extras[key] end |
#each_attribute ⇒ Object
15 16 17 18 19 20 21 22 23 |
# File 'lib/super/form/schema_types.rb', line 15 def each_attribute if block_given? @nested_fields.each do |key, value| yield(key, value) end end enum_for(:each_attribute) end |
#label ⇒ Object
43 44 45 46 47 48 49 50 51 |
# File 'lib/super/form/schema_types.rb', line 43 def label if @extras.key?(:label) return @extras[:label] end if @extras.key?(:reader) return @extras[:reader].to_s.singularize.humanize end end |
#reader ⇒ Object
39 40 41 |
# File 'lib/super/form/schema_types.rb', line 39 def reader @extras[:reader] end |
#to_partial_path ⇒ String
This takes advantage of a feature of Rails. If the value of
#to_partial_path is my_form_field, Rails renders
app/views/super/application/_my_form_field.html.erb, and this
instance of Generic is accessible via my_form_field
31 32 33 |
# File 'lib/super/form/schema_types.rb', line 31 def to_partial_path @partial_path end |