Class: ActiveScaffold::DataStructures::ActionColumns
- Includes:
- Configurable
- Defined in:
- lib/active_scaffold/data_structures/action_columns.rb
Overview
A set of columns. These structures can be nested for organization.
Instance Attribute Summary collapse
-
#action ⇒ Object
this lets us refer back to the action responsible for this link, if it exists.
-
#collapsed ⇒ Object
Whether this column set is collapsed by default in contexts where collapsing is supported.
- #constraint_columns ⇒ Object
- #label ⇒ Object
- #unauthorized_columns ⇒ Object
Instance Method Summary collapse
-
#==(other) ⇒ Object
this is so that array.delete and array.include?, etc., will work by column name.
-
#add_subgroup(label, &proc) ⇒ Object
nests a subgroup in the column set.
- #collect_visible(options = {}, &proc) ⇒ Object
- #css_class ⇒ Object
-
#each(options = {}, &proc) ⇒ Object
Redefine the each method to yield actual Column objects.
- #include?(item) ⇒ Boolean
- #length ⇒ Object
- #names ⇒ Object
- #names_without_auth_check ⇒ Object
-
#set_columns(columns) ⇒ Object
registers a set of column objects (recursively, for all nested ActionColumns).
- #skip_column?(column, options) ⇒ Boolean
Methods included from Configurable
Methods inherited from Set
#add, #empty?, #exclude, #find_by_name, #find_by_names, #initialize, #set_values
Constructor Details
This class inherits a constructor from ActiveScaffold::DataStructures::Set
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class ActiveScaffold::Configurable
Instance Attribute Details
#action ⇒ Object
this lets us refer back to the action responsible for this link, if it exists. the immediate need here is to get the crud_type so we can dynamically filter columns from the set.
8 9 10 |
# File 'lib/active_scaffold/data_structures/action_columns.rb', line 8 def action @action end |
#collapsed ⇒ Object
Whether this column set is collapsed by default in contexts where collapsing is supported
30 31 32 |
# File 'lib/active_scaffold/data_structures/action_columns.rb', line 30 def collapsed @collapsed end |
#constraint_columns ⇒ Object
128 129 130 |
# File 'lib/active_scaffold/data_structures/action_columns.rb', line 128 def constraint_columns @constraint_columns ||= [] end |
#label ⇒ Object
12 13 14 |
# File 'lib/active_scaffold/data_structures/action_columns.rb', line 12 def label as_(@label) if @label end |
#unauthorized_columns ⇒ Object
133 134 135 |
# File 'lib/active_scaffold/data_structures/action_columns.rb', line 133 def @unauthorized_columns ||= [] end |
Instance Method Details
#==(other) ⇒ Object
this is so that array.delete and array.include?, etc., will work by column name
20 21 22 23 24 25 26 27 |
# File 'lib/active_scaffold/data_structures/action_columns.rb', line 20 def ==(other) #:nodoc: # another ActionColumns if other.class == self.class self.label == other.label else @label.to_s == other.to_s end end |
#add_subgroup(label, &proc) ⇒ Object
nests a subgroup in the column set
33 34 35 36 37 38 39 40 |
# File 'lib/active_scaffold/data_structures/action_columns.rb', line 33 def add_subgroup(label, &proc) columns = ActiveScaffold::DataStructures::ActionColumns.new columns.label = label columns.action = self.action columns.configure &proc self.exclude columns.collect_columns self.add columns end |
#collect_visible(options = {}, &proc) ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/active_scaffold/data_structures/action_columns.rb', line 88 def collect_visible( = {}, &proc) columns = [] [:for] ||= @columns.active_record_class self. = [] @set.each do |item| unless item.is_a? ActiveScaffold::DataStructures::ActionColumns || @columns.nil? item = (@columns[item] || ActiveScaffold::DataStructures::Column.new(item.to_sym, @columns.active_record_class)) next if self.skip_column?(item, ) end if item.is_a? ActiveScaffold::DataStructures::ActionColumns and .has_key?(:flatten) and [:flatten] columns += item.collect_visible(, &proc) else columns << (block_given? ? yield(item) : item) end end columns end |
#css_class ⇒ Object
15 16 17 |
# File 'lib/active_scaffold/data_structures/action_columns.rb', line 15 def css_class @label.to_s.underscore 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.
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/active_scaffold/data_structures/action_columns.rb', line 68 def each( = {}, &proc) [:for] ||= @columns.active_record_class unless @columns.nil? self. = [] @set.each do |item| unless item.is_a?(ActiveScaffold::DataStructures::ActionColumns) || @columns.nil? item = (@columns[item] || ActiveScaffold::DataStructures::Column.new(item.to_sym, @columns.active_record_class)) next if self.skip_column?(item, ) end if item.is_a? ActiveScaffold::DataStructures::ActionColumns if [:flatten] item.each(, &proc) elsif ![:skip_groups] yield item end else yield item end end end |
#include?(item) ⇒ Boolean
42 43 44 45 46 47 48 |
# File 'lib/active_scaffold/data_structures/action_columns.rb', line 42 def include?(item) @set.each do |c| return true if !c.is_a? Symbol and c.include? item return true if c == item.to_sym end return false end |
#length ⇒ Object
137 138 139 |
# File 'lib/active_scaffold/data_structures/action_columns.rb', line 137 def length ((@set - self.constraint_columns) - self.).length end |
#names ⇒ Object
50 51 52 53 54 55 56 |
# File 'lib/active_scaffold/data_structures/action_columns.rb', line 50 def names if @columns self.collect_visible(:flatten => true) { |c| c.name } else names_without_auth_check end end |
#names_without_auth_check ⇒ Object
58 59 60 |
# File 'lib/active_scaffold/data_structures/action_columns.rb', line 58 def names_without_auth_check Array(@set) end |
#set_columns(columns) ⇒ Object
registers a set of column objects (recursively, for all nested ActionColumns)
119 120 121 122 123 124 125 |
# File 'lib/active_scaffold/data_structures/action_columns.rb', line 119 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
106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/active_scaffold/data_structures/action_columns.rb', line 106 def skip_column?(column, ) result = false # skip if this matches a constrained column result = true if constraint_columns.include?(column.name.to_sym) # skip this field if it's not authorized unless [:for].(:action => [:action], :crud_type => [:crud_type] || self.action.try(:crud_type), :column => column.name) self. << column.name.to_sym result = true end return result end |