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



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

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

Instance Attribute Details

#default_model_classObject

returns the main ActiveRecord model class



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

def default_model_class
  @default_model_class
end

#generated_conditionsObject (readonly)

a structure to hold generates Arels for all column filters



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

def generated_conditions
  @generated_conditions
end

Instance Method Details

#[](model) ⇒ Object

:nodoc:



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

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



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

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

#conditionsObject

returns a list of all Arels



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

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

#getObject

returns Arels for one model



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

alias_method :get, :[]

#get_column_by_model_class_and_column_name(model_class, column_name) ⇒ Object

:nodoc:



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

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:



45
46
47
48
49
50
51
# File 'lib/wice/table_column_matrix.rb', line 45

def get_column_in_default_model_class_by_column_name(column_name)  #:nodoc:
  if @default_model_class.nil?
    raise 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:



53
54
55
56
57
58
# File 'lib/wice/table_column_matrix.rb', line 53

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