Module: ActiveScaffold::DataStructures::ActionColumns::AfterConfiguration
- Defined in:
- lib/active_scaffold/data_structures/action_columns.rb
Overview
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.
Instance Attribute Summary collapse
Instance Method Summary collapse
- #collect_visible(options = {}, &proc) ⇒ Object
-
#each(options = {}, &proc) ⇒ Object
Redefine the each method to yield actual Column objects.
- #length ⇒ Object
-
#set_columns(columns) ⇒ Object
registers a set of column objects (recursively, for all nested ActionColumns).
- #skip_column?(column, options) ⇒ Boolean
Instance Attribute Details
#constraint_columns ⇒ Object
161 162 163 |
# File 'lib/active_scaffold/data_structures/action_columns.rb', line 161 def constraint_columns @constraint_columns ||= [] end |
#unauthorized_columns ⇒ Object
166 167 168 |
# File 'lib/active_scaffold/data_structures/action_columns.rb', line 166 def @unauthorized_columns ||= [] end |
Instance Method Details
#collect_visible(options = {}, &proc) ⇒ Object
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/active_scaffold/data_structures/action_columns.rb', line 121 def collect_visible( = {}, &proc) self.convert_to_columns unless columns_converted? columns = [] [:for] ||= @columns.active_record_class self. = [] @set.each do |item| case item when ActiveScaffold::DataStructures::Column self.skip_column?(item, ) ? next : (columns << item) when ActiveScaffold::DataStructures::ActionColumns [:flatten] ? item.collect(, &proc) : (columns << item) end end columns end |
#each(options = {}, &proc) ⇒ Object
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.
107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/active_scaffold/data_structures/action_columns.rb', line 107 def each( = {}, &proc) self.convert_to_columns unless columns_converted? [:for] ||= @columns.active_record_class self. = [] @set.each do |item| case item when ActiveScaffold::DataStructures::Column self.skip_column?(item, ) ? next : (yield item) when ActiveScaffold::DataStructures::ActionColumns [:flatten] ? item.each(, &proc) : (yield item) end end end |
#length ⇒ Object
170 171 172 |
# File 'lib/active_scaffold/data_structures/action_columns.rb', line 170 def length ((@set - self.constraint_columns) - self.).length end |
#set_columns(columns) ⇒ Object
registers a set of column objects (recursively, for all nested ActionColumns)
152 153 154 155 156 157 158 |
# 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) ⇒ Boolean
137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/active_scaffold/data_structures/action_columns.rb', line 137 def skip_column?(column, ) 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 [:for].(:action => [:action], :crud_type => [:crud_type] || self.action.crud_type, :column => column.name) self. << column.name.to_sym result = true end return result end |