class ActiveScaffold::DataStructures::ActionColumns

A set of columns. These structures can be nested for organization.

Attributes

action[RW]

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.

collapsed[RW]

Whether this column set is collapsed by default in contexts where collapsing is supported

label[W]

labels are useful for the Create/Update forms, when we display columns in a grouped fashion and want to name them separately

Public Instance Methods

add_subgroup(label, insert_index = nil, &proc) click to toggle source

nests a subgroup in the column set

# File lib/active_scaffold/data_structures/action_columns.rb, line 22
def add_subgroup(label, insert_index = nil, &proc)
  columns = ActiveScaffold::DataStructures::ActionColumns.new
  columns.label = label
  columns.action = self.action
  columns.configure &proc
  self.exclude columns.collect_columns
  if insert_index.nil?
    self.add columns
  else
    self.add columns, insert_index
  end

end
include?(item) click to toggle source
# File lib/active_scaffold/data_structures/action_columns.rb, line 36
def include?(item)
  @set.any? do |c|
    case c
    when Symbol
      c == item.to_sym
    when ActiveScaffold::DataStructures::Column
      c.name == item.to_sym
    when ActiveScaffold::DataStructures::ActionColumns
      !c.is_a? Symbol and c.include? item
    end
  end
end
label() click to toggle source
# File lib/active_scaffold/data_structures/action_columns.rb, line 12
def label
  as_(@label) if @label
end
Also aliased as: name
name()
Alias for: label
names() click to toggle source
# File lib/active_scaffold/data_structures/action_columns.rb, line 49
def names
  self.collect(&:name)
end
names_without_auth_check() click to toggle source
# File lib/active_scaffold/data_structures/action_columns.rb, line 53
def names_without_auth_check
  Array(@set)
end
select(&block) click to toggle source
# File lib/active_scaffold/data_structures/action_columns.rb, line 57
def select(&block)
  self.convert_to_columns unless columns_converted?
  #columns = ActiveScaffold::DataStructures::ActionColumns.new
  columns = self.clone
  #ActiveScaffold::DataStructures::ActionColumns.class_eval {include ActiveScaffold::DataStructures::ActionColumns::AfterConfiguration}
  #columns.label = self.label
  #columns.action = self.action
  columns.instance_variable_get('@set').clear
  cols = @set.select &block

  columns.add cols
  columns
end

Protected Instance Methods

collect_columns() click to toggle source
# File lib/active_scaffold/data_structures/action_columns.rb, line 73
def collect_columns
  @set.collect {|col| col.is_a?(ActiveScaffold::DataStructures::ActionColumns) ? col.collect_columns : col}
end
columns_converted?() click to toggle source
# File lib/active_scaffold/data_structures/action_columns.rb, line 94
def columns_converted?
  @columns_converted
end
convert_to_columns() click to toggle source

at the beginning items are only symbolized column names to allow easy configuration later on we need ActiveScaffold::Datastructures:ActionColumn

# File lib/active_scaffold/data_structures/action_columns.rb, line 84
def convert_to_columns
  @set.collect! do|item|
    unless item.is_a? ActiveScaffold::DataStructures::ActionColumns
      item = (@columns[item] || ActiveScaffold::DataStructures::Column.new(item.to_sym, @columns.active_record_class))
    end
    item
  end
  @columns_converted = true
end
initialize_copy(from) click to toggle source

called during clone or dup. makes the clone/dup deeper.

# File lib/active_scaffold/data_structures/action_columns.rb, line 78
def initialize_copy(from)
  @set = from.instance_variable_get('@set').clone
end