lib/netzke/data_accessor.rb in netzke-basepack-0.5.8 vs lib/netzke/data_accessor.rb in netzke-basepack-0.5.9

- old
+ new

@@ -12,42 +12,19 @@ # 2) generic (used by all "data accessor" widgets) extensions into the data model for this widget def apply_helpers # Generic extensions to the data model if data_class # because some widgets, like FormPanel, may have it optional data_class.send(:include, Netzke::ActiveRecord::DataAccessor) if !data_class.include?(Netzke::ActiveRecord::DataAccessor) - - # Model helpers - const_name = "Netzke::Helpers::#{data_class.name}" - model_extensions = const_name.constantize rescue nil - data_class.send(:include, model_extensions) if model_extensions && !data_class.include?(model_extensions) end end - - # Returns columns that are exposed by the class and the helpers - def predefined_columns - helper_module = "Netzke::Helpers::#{short_widget_class_name}#{data_class.name}".constantize rescue nil - - data_class_columns = data_class && data_class.column_names.map(&:to_sym) || [] - - if helper_module - exposed_attributes = helper_module.respond_to?(:exposed_attributes) ? normalize_array_of_columns(helper_module.exposed_attributes) : nil - virtual_attributes = helper_module.respond_to?(:virtual_attributes) ? helper_module.virtual_attributes : [] - excluded_attributes = helper_module.respond_to?(:excluded_attributes) ? helper_module.excluded_attributes : [] - attributes_config = helper_module.respond_to?(:attributes_config) ? helper_module.attributes_config : {} - - res = exposed_attributes || data_class_columns + virtual_attributes - - res = normalize_columns(res) - - res.reject!{ |c| excluded_attributes.include? c[:name] } - - res.map!{ |c| c.merge!(attributes_config[c[:name]] || {})} - else - res = normalize_columns(data_class_columns) + + # [:col1, "col2", {:name => :col3}] => + # [{:name => "col1"}, {:name => "col2"}, {:name => "col3"}] + def normalize_attr_config(cols) + cols.map do |c| + c.is_a?(Symbol) || c.is_a?(String) ? {:name => c.to_s} : c.merge(:name => c[:name].to_s) end - - res end # Make sure we have keys as symbols, not strings def normalize_array_of_columns(arry) arry.map do |f| @@ -59,10 +36,10 @@ end end # From symbol to config hash def normalize_column(field) - field.is_a?(Symbol) ? {:name => field} : field + field.is_a?(Symbol) ? {:name => field.to_s} : field end # From symbols to config hashes def normalize_columns(items) items.map{|c| normalize_column(c)} \ No newline at end of file