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



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

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

Instance Attribute Details

#default_model_classObject

returns the main ActiveRecord model class



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

def default_model_class
  @default_model_class
end

#generated_conditionsObject (readonly)

a structure to hold generates Arels for all column filters



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

def generated_conditions
  @generated_conditions
end

Instance Method Details

#[](model) ⇒ Object

returns Arels for one model



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

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



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

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

#conditionsObject

returns a list of all Arels



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

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

#getObject

returns Arels for one model



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

alias_method :get, :[]

#get_column_by_model_class_and_column_name(model_class, column_name) ⇒ Object

:nodoc:



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

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:



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

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:



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

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