module ActiveScaffold::DataStructures::ActionColumns::AfterConfiguration
A package of stuff to add after the configuration block. This is an attempt at making a certain level of functionality inaccessible during configuration, to reduce possible breakage from misuse. The bulk of the package is a means of connecting the referential column set (ActionColumns
) with the actual column objects (Columns
). This lets us iterate over the set and yield real column objects.
Attributes
constraint_columns[W]
Public Instance Methods
collect_visible(options = {}, &proc)
click to toggle source
# File lib/active_scaffold/data_structures/action_columns.rb, line 121 def collect_visible(options = {}, &proc) self.convert_to_columns unless columns_converted? columns = [] options[:for] ||= @columns.active_record_class self.unauthorized_columns = [] @set.each do |item| case item when ActiveScaffold::DataStructures::Column self.skip_column?(item, options) ? next : (columns << item) when ActiveScaffold::DataStructures::ActionColumns options[:flatten] ? item.collect(options, &proc) : (columns << item) end end columns end
constraint_columns()
click to toggle source
# File lib/active_scaffold/data_structures/action_columns.rb, line 161 def constraint_columns @constraint_columns ||= [] end
each(options = {}) { |item)| ... }
click to toggle source
Redefine the each method to yield actual Column
objects. It will skip constrained and unauthorized columns.
Options:
* :flatten - whether to recursively iterate on nested sets. default is false. * :for - the record (or class) being iterated over. used for column-level security. default is the class.
# File lib/active_scaffold/data_structures/action_columns.rb, line 107 def each(options = {}, &proc) self.convert_to_columns unless columns_converted? options[:for] ||= @columns.active_record_class self.unauthorized_columns = [] @set.each do |item| case item when ActiveScaffold::DataStructures::Column self.skip_column?(item, options) ? next : (yield item) when ActiveScaffold::DataStructures::ActionColumns options[:flatten] ? item.each(options, &proc) : (yield item) end end end
length()
click to toggle source
# File lib/active_scaffold/data_structures/action_columns.rb, line 170 def length ((@set - self.constraint_columns) - self.unauthorized_columns).length end
set_columns(columns)
click to toggle source
registers a set of column objects (recursively, for all nested ActionColumns
)
# File lib/active_scaffold/data_structures/action_columns.rb, line 152 def set_columns(columns) @columns = columns # iterate over @set instead of self to avoid dealing with security queries @set.each do |item| item.set_columns(columns) if item.respond_to? :set_columns end end
skip_column?(column, options)
click to toggle source
# File lib/active_scaffold/data_structures/action_columns.rb, line 137 def skip_column?(column, options) result = false # skip if this matches a constrained column result = true if constraint_columns.include?(column.name.to_sym) # skip if this matches the field_name of a constrained column result = true if column.field_name and constraint_columns.include?(column.field_name.to_sym) # skip this field if it's not authorized unless options[:for].authorized_for?(:action => options[:action], :crud_type => options[:crud_type] || self.action.crud_type, :column => column.name) self.unauthorized_columns << column.name.to_sym result = true end return result end