Module: Netzke::Basepack::DataAccessor

Included in:
FormPanel, GridPanel, SearchPanel
Defined in:
lib/netzke/basepack/data_accessor.rb

Overview

This module is included into such data-driven components as GridPanel, FormPanel, PagingFormPanel, etc.

Instance Method Summary collapse

Instance Method Details

#association_attr?(name) ⇒ Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/netzke/basepack/data_accessor.rb', line 27

def association_attr?(name)
  !!name.to_s.index("__")
end

#combobox_options_for_column(column, method_options = {}) ⇒ Object

Returns options for comboboxes in grids/forms



9
10
11
# File 'lib/netzke/basepack/data_accessor.rb', line 9

def combobox_options_for_column(column, method_options = {})
  data_adapter.combobox_options_for_column column, method_options
end

#data_adapterObject

Data adapter responsible for all DB-related operations



37
38
39
# File 'lib/netzke/basepack/data_accessor.rb', line 37

def data_adapter
  @data_adapter ||= Netzke::Basepack::DataAdapters::AbstractAdapter.adapter_class(data_class).new(data_class)
end

#data_classObject

Model class



32
33
34
# File 'lib/netzke/basepack/data_accessor.rb', line 32

def data_class
  @data_class ||= config[:model].is_a?(String) ? config[:model].constantize : config[:model]
end

#normalize_attr(a) ⇒ Object

Normalize an attribute, e.g.: :first_name =>

{:name => "first_name"}


23
24
25
# File 'lib/netzke/basepack/data_accessor.rb', line 23

def normalize_attr(a)
  a.is_a?(Symbol) || a.is_a?(String) ? {:name => a.to_s} : a.merge(:name => a[:name].to_s)
end

#normalize_attrs(attrs) ⇒ Object

Normalize array of attributes

:col1, “col2”, => :col3

>

=> “col1”, => “col2”, => “col3”


16
17
18
# File 'lib/netzke/basepack/data_accessor.rb', line 16

def normalize_attrs(attrs)
  attrs.map{ |a| normalize_attr(a) }
end

#primary_key_attr?(a) ⇒ Boolean

whether a column is bound to the primary_key

Returns:

  • (Boolean)


42
43
44
# File 'lib/netzke/basepack/data_accessor.rb', line 42

def primary_key_attr?(a)
  data_class && a[:name].to_s == data_class.primary_key.to_s
end

#set_default_virtual(c) ⇒ Object

Mark an attribute as “virtual” by default, when it doesn’t reflect a model column, or a model column of an association



47
48
49
# File 'lib/netzke/basepack/data_accessor.rb', line 47

def set_default_virtual(c)
  c[:virtual] = data_adapter.column_virtual?(c) if c[:virtual].nil?
end