Class: Super::Form::SchemaTypes::Generic

Inherits:
Object
  • Object
show all
Defined in:
lib/super/form/schema_types.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(partial_path:, extras:, nested:) ⇒ Generic

Returns a new instance of Generic.



26
27
28
29
30
# File 'lib/super/form/schema_types.rb', line 26

def initialize(partial_path:, extras:, nested:)
  @partial_path = partial_path
  @extras = extras
  @nested_fields = nested
end

Instance Attribute Details

#nested_fieldsObject (readonly)

Returns the value of attribute nested_fields.



32
33
34
# File 'lib/super/form/schema_types.rb', line 32

def nested_fields
  @nested_fields
end

Instance Method Details

#==(other) ⇒ Object



62
63
64
65
66
67
68
69
# File 'lib/super/form/schema_types.rb', line 62

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) != @nested

  true
end

#[](key) ⇒ Object



44
45
46
# File 'lib/super/form/schema_types.rb', line 44

def [](key)
  @extras[key]
end

#labelObject



52
53
54
55
56
57
58
59
60
# File 'lib/super/form/schema_types.rb', line 52

def label
  if @extras.key?(:label)
    return @extras[:label]
  end

  if @extras.key?(:reader)
    return @extras[:reader].to_s.singularize.humanize
  end
end

#readerObject



48
49
50
# File 'lib/super/form/schema_types.rb', line 48

def reader
  @extras[:reader]
end

#to_partial_pathString

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`

Returns:

  • (String)

    the filename of the partial that will be rendered.



40
41
42
# File 'lib/super/form/schema_types.rb', line 40

def to_partial_path
  @partial_path
end