Class: Flexite::ArrEntry

Inherits:
Entry
  • Object
show all
Defined in:
app/models/flexite/arr_entry.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from WithHistory

#restore

Class Method Details

.form(attributes = {}) ⇒ Object



17
18
19
# File 'app/models/flexite/arr_entry.rb', line 17

def self.form(attributes = {})
  Entry::ArrayForm.new(attributes)
end

.service(type) ⇒ Object



21
22
23
# File 'app/models/flexite/arr_entry.rb', line 21

def self.service(type)
  "arr_entry_#{type}".to_sym
end

Instance Method Details

#dig(level) ⇒ Object



35
36
37
38
39
40
41
# File 'app/models/flexite/arr_entry.rb', line 35

def dig(level)
  if level.to_sym == :entries
    return send(level).order_by_value
  end

  super
end

#entry=(entry) ⇒ Object



9
10
11
# File 'app/models/flexite/arr_entry.rb', line 9

def entry=(entry)
  entries << entry
end

#form_attributesObject



13
14
15
# File 'app/models/flexite/arr_entry.rb', line 13

def form_attributes
  attributes.merge(entries: form_entries)
end

#t_nodeObject



25
26
27
28
29
30
31
32
33
# File 'app/models/flexite/arr_entry.rb', line 25

def t_node
  node = super.except('value')

  if entries.any?
    node.merge!('entries' => entries.order_by_value.map(&:t_node))
  end

  node
end

#valueObject



5
6
7
# File 'app/models/flexite/arr_entry.rb', line 5

def value
  entries.select([:id, :value, :type]).map(&:value)
end