Module: Netzke::ActiveRecord::DataAccessor

Defined in:
lib/netzke/active_record/data_accessor.rb

Overview

Provides extensions to those ActiveRecord-based models that provide data to the “data accessor” widgets, like GridPanel, FormPanel, etc

Instance Method Summary collapse

Instance Method Details

#netzke_widgetObject



12
13
14
# File 'lib/netzke/active_record/data_accessor.rb', line 12

def netzke_widget
  @netzke_widget
end

#netzke_widget=(widget) ⇒ Object

Allow specify the netzke widget that requires this data. Virtual attributes may be using it to produce widget-dependent result.



8
9
10
# File 'lib/netzke/active_record/data_accessor.rb', line 8

def netzke_widget=(widget)
  @netzke_widget = widget
end

#to_array(columns, widget = nil) ⇒ Object

Transforms a record to array of values according to the passed columns.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/netzke/active_record/data_accessor.rb', line 17

def to_array(columns, widget = nil)
  self.netzke_widget = widget
  res = []
  for c in columns
    nc = c.is_a?(Symbol) ? {:name => c} : c
    begin
      res << send(nc[:name]) unless nc[:excluded]
    rescue
      # So that we don't crash at a badly configured column
      res << "UNDEF"
    end
  end
  res
end