Class: Wice::TableColumnMatrix

Inherits:
Hash
  • Object
show all
Defined in:
lib/wice/table_column_matrix.rb

Overview

a matrix for all declared columns

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeTableColumnMatrix

init a matrix of all columns



11
12
13
14
15
# File 'lib/wice/table_column_matrix.rb', line 11

def initialize  #:nodoc:
  super
  @generated_conditions = []
  @by_table_names = HashWithIndifferentAccess.new
end

Instance Attribute Details

#default_model_classObject

returns the main ActiveRecord model class



31
32
33
# File 'lib/wice/table_column_matrix.rb', line 31

def default_model_class
  @default_model_class
end

#generated_conditionsObject (readonly)

a structure to hold generates Arels for all column filters



8
9
10
# File 'lib/wice/table_column_matrix.rb', line 8

def generated_conditions
  @generated_conditions
end

Instance Method Details

#[](model) ⇒ Object

returns Arels for one model



40
41
42
43
# File 'lib/wice/table_column_matrix.rb', line 40

def [](model)  #:nodoc:
  init_columns_of_table(model) unless key?(model)
  get(model)
end

#add_condition(column, conditions) ⇒ Object

add an Arel for a column



18
19
20
# File 'lib/wice/table_column_matrix.rb', line 18

def add_condition(column, conditions)
  @generated_conditions << [column, conditions] unless conditions.blank?
end

#conditionsObject

returns a list of all Arels



23
24
25
# File 'lib/wice/table_column_matrix.rb', line 23

def conditions
  @generated_conditions.collect { |_, cond| cond }
end

#getObject

returns Arels for one model



28
# File 'lib/wice/table_column_matrix.rb', line 28

alias_method :get, :[]

#get_column_by_model_class_and_column_name(model_class, column_name) ⇒ Object

:nodoc:



45
46
47
# File 'lib/wice/table_column_matrix.rb', line 45

def get_column_by_model_class_and_column_name(model_class, column_name)  #:nodoc:
  self[model_class][column_name]
end

#get_column_in_default_model_class_by_column_name(column_name) ⇒ Object

:nodoc:



49
50
51
52
53
54
55
# File 'lib/wice/table_column_matrix.rb', line 49

def get_column_in_default_model_class_by_column_name(column_name)  #:nodoc:
  if @default_model_class.nil?
    fail WiceGridException.new("Cannot search for this column(#{column_name}) in a default model(#{@default_model_class}) as the default model is not set")
  end

  self[@default_model_class][column_name]
end

#init_columns_of_table(model) ⇒ Object Also known as: <<

:nodoc:



57
58
59
60
61
# File 'lib/wice/table_column_matrix.rb', line 57

def init_columns_of_table(model) #:nodoc:
  self[model] = HashWithIndifferentAccess.new(model.columns.index_by(&:name))
  @by_table_names[model.table_name] = self[model]
  self[model].each_value { |c| c.model = model }
end