Class: KonoUtilsBootstrapView4::EditableField

Inherits:
Object
  • Object
show all
Defined in:
lib/kono_utils_bootstrap_view4/editable_field.rb

Overview

PORO che si occupa di gestire un campo da editare. questo serve per poter gestire le casistiche provenienti dagli editable attributes, che consistono in semplisy symbols o in hash che rappresentano le relazioni

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(f) ⇒ EditableField

Returns a new instance of EditableField.



10
11
12
# File 'lib/kono_utils_bootstrap_view4/editable_field.rb', line 10

def initialize(f)
  @field = f
end

Class Method Details

.editable_fields_to_field_array(attributes) ⇒ Array<KonoUtilsBootstrapView4::EditableField>



50
51
52
53
54
55
56
57
58
59
60
# File 'lib/kono_utils_bootstrap_view4/editable_field.rb', line 50

def self.editable_fields_to_field_array(attributes)
  attributes.collect do |s|

    if s.is_a?(Hash)
      s.collect {|k, v| KonoUtilsBootstrapView4::EditableField.new({k => v})}
    else
      KonoUtilsBootstrapView4::EditableField.new(s)
    end

  end.flatten
end

Instance Method Details

#inner_fieldsObject

Nei casi di campi nested, questo metodo restituisce un array di campi interni, normalizzati a EditableField



44
45
46
# File 'lib/kono_utils_bootstrap_view4/editable_field.rb', line 44

def inner_fields
  is_nested? ? self.class.editable_fields_to_field_array(@field[name]) : []
end

#is_hidden?TrueClass|FalseClass

Solitamente questi campi sono da renderizzare come nascosti

Returns:

  • (TrueClass|FalseClass)


32
33
34
# File 'lib/kono_utils_bootstrap_view4/editable_field.rb', line 32

def is_hidden?
  ['id', '_destroy'].include?(name.to_s)
end

#is_nested?Boolean

Controlla se il campo è di tipo nested (un hash con chiave ed una serie di campi interni)

Returns:

  • (Boolean)


38
39
40
# File 'lib/kono_utils_bootstrap_view4/editable_field.rb', line 38

def is_nested?
  @field.is_a?(Hash)
end

#nameObject

Restituisce il symbol che rappresenta il campo da editare



18
19
20
21
22
23
24
25
26
# File 'lib/kono_utils_bootstrap_view4/editable_field.rb', line 18

def name

  if @field.is_a?(Hash)
    @field.keys.first
  else
    @field.to_sym
  end

end