Class: Wice::TableColumnMatrix

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

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from WGHashExtensions

#add_or_append_class_value!, #deep_clone_yl, included, #parameter_names_and_values, #rec_merge

Constructor Details

#initializeTableColumnMatrix

:nodoc:


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

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


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

def default_model_class
  @default_model_class
end

#generated_conditionsObject (readonly)

Returns the value of attribute generated_conditions


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

def generated_conditions
  @generated_conditions
end

Instance Method Details

#[](model_klass) ⇒ Object

:nodoc:


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

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

#add_condition(column, conditions) ⇒ Object


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

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

#conditionsObject


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

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

#getObject


21
# File 'lib/table_column_matrix.rb', line 21

alias_method :get, :[]

#get_column_by_model_class_and_column_name(model_class, column_name) ⇒ Object

:nodoc:


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

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:


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

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_klass) ⇒ Object Also known as: <<

:nodoc:


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

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