Sha256: f4d960346a3adb3a48a6720b3d3ecb761148d4d808db4886b3002c7d597a3b18

Contents?: true

Size: 1.46 KB

Versions: 26

Compression:

Stored size: 1.46 KB

Contents

# encoding: UTF-8
module Wice
  class TableColumnMatrix < Hash #:nodoc:

    attr_reader :generated_conditions

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

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

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

    alias_method :get, :[]

    attr_reader :default_model_class
    def default_model_class=(model)  #:nodoc:
      init_columns_of_table(model) unless has_key?(model)
      @default_model_class = model
    end

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

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

    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

    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
    alias_method :<< , :init_columns_of_table

  end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
wice_grid-3.4.14 lib/wice/table_column_matrix.rb
wice_grid-3.4.13 lib/wice/table_column_matrix.rb
wice_grid-3.4.12 lib/wice/table_column_matrix.rb
wice_grid-3.4.11 lib/wice/table_column_matrix.rb
wice_grid-3.4.10 lib/wice/table_column_matrix.rb
wice_grid-3.4.9 lib/wice/table_column_matrix.rb
wice_grid-3.4.8 lib/wice/table_column_matrix.rb
wice_grid-3.4.7 lib/wice/table_column_matrix.rb
wice_grid-3.4.6 lib/wice/table_column_matrix.rb
wice_grid-3.4.5 lib/wice/table_column_matrix.rb
wice_grid-3.4.4 lib/wice/table_column_matrix.rb
wice_grid-3.4.3 lib/wice/table_column_matrix.rb
wice_grid-3.4.2 lib/wice/table_column_matrix.rb
wice_grid-3.4.1 lib/wice/table_column_matrix.rb
wice_grid-3.4.0 lib/wice/table_column_matrix.rb
wice_grid-3.3.1 lib/wice/table_column_matrix.rb
wice_grid-3.3.0 lib/wice/table_column_matrix.rb
wice_grid-3.2.1 lib/table_column_matrix.rb
wice_grid-3.2.1.pre3 lib/table_column_matrix.rb
wice_grid-3.2.1.pre2 lib/table_column_matrix.rb