Class: Wice::TableColumnMatrix

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

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeTableColumnMatrix

:nodoc:



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

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

Instance Attribute Details

#default_model_classObject

Returns the value of attribute default_model_class.



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

def default_model_class
  @default_model_class
end

#generated_conditionsObject (readonly)

Returns the value of attribute generated_conditions.



4
5
6
# File 'lib/wice/table_column_matrix.rb', line 4

def generated_conditions
  @generated_conditions
end

Instance Method Details

#[](model) ⇒ Object

:nodoc:



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

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

#add_condition(column, conditions) ⇒ Object



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

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

#conditionsObject



16
17
18
# File 'lib/wice/table_column_matrix.rb', line 16

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

#getObject



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

alias_method :get, :[]

#get_column_by_model_class_and_column_name(model_class, column_name) ⇒ Object

:nodoc:



33
34
35
# File 'lib/wice/table_column_matrix.rb', line 33

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:

Raises:



37
38
39
40
# File 'lib/wice/table_column_matrix.rb', line 37

def get_column_in_default_model_class_by_column_name(column_name)  #:nodoc:
  raise WiceGridException.new("Cannot search for a column in a default model as the default model is not set") if @default_model_class.nil?
  self[@default_model_class][column_name]
end

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

:nodoc:



42
43
44
45
46
# File 'lib/wice/table_column_matrix.rb', line 42

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