Class: Super::Form::SchemaTypes::Generic
- Inherits:
-
Object
- Object
- Super::Form::SchemaTypes::Generic
- Defined in:
- lib/super/form/schema_types.rb
Instance Attribute Summary collapse
-
#extras ⇒ Object
readonly
Returns the value of attribute extras.
-
#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.
39 40 41 42 43 |
# File 'lib/super/form/schema_types.rb', line 39 def initialize(partial_path:, extras:, nested:) @partial_path = partial_path @extras = extras @nested_fields = nested end |
Instance Attribute Details
#extras ⇒ Object (readonly)
Returns the value of attribute extras.
46 47 48 |
# File 'lib/super/form/schema_types.rb', line 46 def extras @extras end |
#nested_fields ⇒ Object (readonly)
Returns the value of attribute nested_fields.
45 46 47 |
# File 'lib/super/form/schema_types.rb', line 45 def nested_fields @nested_fields end |
Instance Method Details
#==(other) ⇒ Object
86 87 88 89 90 91 92 93 |
# File 'lib/super/form/schema_types.rb', line 86 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
68 69 70 |
# File 'lib/super/form/schema_types.rb', line 68 def [](key) @extras[key] end |
#each_attribute ⇒ Object
48 49 50 51 52 53 54 55 56 |
# File 'lib/super/form/schema_types.rb', line 48 def each_attribute if block_given? @nested_fields.each do |key, value| yield(key, value) end end enum_for(:each_attribute) end |
#label ⇒ Object
76 77 78 79 80 81 82 83 84 |
# File 'lib/super/form/schema_types.rb', line 76 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
72 73 74 |
# File 'lib/super/form/schema_types.rb', line 72 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
64 65 66 |
# File 'lib/super/form/schema_types.rb', line 64 def to_partial_path @partial_path end |