Class: HakumiComponents::Table::Configs::Editable

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
app/components/hakumi_components/table/configs.rb

Constant Summary collapse

MODES =
T.let(%i[cell row].freeze, T::Array[Symbol])
TRIGGERS =
T.let(%i[click dblclick].freeze, T::Array[Symbol])
InputScalar =
T.type_alias { T.any(T::Boolean, Types::HtmlKey) }
Payload =
T.type_alias { T::Hash[Symbol, Types::HtmlKey] }
Input =
T.type_alias { T.nilable(T.any(InputScalar, InputHash, HakumiComponents::Table::Configs::Editable)) }

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(mode: :cell, trigger: :click) ⇒ Editable

Returns a new instance of Editable.



20
21
22
23
# File 'app/components/hakumi_components/table/configs.rb', line 20

def initialize(mode: :cell, trigger: :click)
  @mode = T.let(MODES.include?(mode) ? mode : :cell, Symbol)
  @trigger = T.let(TRIGGERS.include?(trigger) ? trigger : :click, Symbol)
end

Instance Attribute Details

#modeObject (readonly)

Returns the value of attribute mode.



26
27
28
# File 'app/components/hakumi_components/table/configs.rb', line 26

def mode
  @mode
end

#triggerObject (readonly)

Returns the value of attribute trigger.



26
27
28
# File 'app/components/hakumi_components/table/configs.rb', line 26

def trigger
  @trigger
end

Class Method Details

.coerce(value) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'app/components/hakumi_components/table/configs.rb', line 34

def self.coerce(value)
  return nil if value.nil? || value == false
  return new if value == true
  return value if value.is_a?(HakumiComponents::Table::Configs::Editable)

  if value.is_a?(String) || value.is_a?(Symbol)
    return new(mode: normalize_mode(value))
  end

  return nil unless value.is_a?(Hash)

  normalized = value.deep_symbolize_keys
  new(
    mode: normalize_mode(normalized[:mode]),
    trigger: normalize_trigger(normalized[:trigger])
  )
end

Instance Method Details

#to_hObject



29
30
31
# File 'app/components/hakumi_components/table/configs.rb', line 29

def to_h
  { mode: @mode, trigger: @trigger }
end