Class: Fiona7::AttributeWriters::WidgetlistAsLinklist

Inherits:
AttributeWriter show all
Defined in:
lib/fiona7/attribute_writers/widgetlist_as_linklist.rb

Instance Method Summary collapse

Methods inherited from AttributeWriter

#initialize

Constructor Details

This class inherits a constructor from Fiona7::AttributeWriters::AttributeWriter

Instance Method Details

#call(value, claimed_type = nil) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/fiona7/attribute_writers/widgetlist_as_linklist.rb', line 6

def call(value, claimed_type=nil)
  # TODO: widget_respository
  links = []
  if value.kind_of?(Array)
    (value || []).each do  |widget_id|
      if (path=self.widget_map[widget_id]||self.widget_map[widget_id.to_s])
        links << {destination_object: path, title: widget_id}
      else
        raise Scrivito::ScrivitoError, "Inconsistent widget pool state detected, unable to store widgets (unable to find #{widget_id} in #{self.widget_map.inspect})"
      end
    end
  elsif value.kind_of?(Hash)
    # stupid shits could not use one consistent format
    (value || {})["list"].each do  |crap|
      widget_id = crap["widget"]
      if (path=self.widget_map[widget_id]||self.widget_map[widget_id.to_s])
        links << {destination_object: path, title: widget_id}
      else
        raise Scrivito::ScrivitoError, "Inconsistent widget pool state detected, unable to store widgets (unable to find #{widget_id} in #{self.widget_map.inspect})"
      end
    end
  end
  self.obj.set(self.attr_name, links)
end