Module: BigRecord::FamilySpanColumns

Defined in:
lib/big_record/family_span_columns.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary

Instance Method Summary

Class Method Details

+ (Object) included(base)

:nodoc:



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/big_record/family_span_columns.rb', line 5

def self.included(base) #:nodoc:
  super
  base.alias_method_chain :column_for_attribute, :family_span_columns
  base.alias_method_chain :attributes_from_column_definition, :family_span_columns

  base.extend(ClassMethods)
  base.class_eval do
    class << self
      alias_method_chain :alias_attribute, :family_span_columns
    end
  end
end

Instance Method Details

- (Object) attributes_from_column_definition_with_family_span_columns

Initializes the attributes array with keys matching the columns from the linked table and the values matching the corresponding default value of that column, so that a new instance, or one populated from a passed-in Hash, still has all the attributes that instances loaded from the database would.



80
81
82
83
84
85
86
87
# File 'lib/big_record/family_span_columns.rb', line 80

def attributes_from_column_definition_with_family_span_columns
  self.simple_columns.inject({}) do |attributes, column|
    unless column.name == self.class.primary_key or column.family?
      attributes[column.name] = column.default
    end
    attributes
  end
end

- (Object) column_for_attribute_with_family_span_columns(name)

Returns the column object for the named attribute.



62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/big_record/family_span_columns.rb', line 62

def column_for_attribute_with_family_span_columns(name)
  name = name.to_s

  # ignore methods '=' and '?' (e.g. 'normalized_srf_ief:231=')
  return if name =~ /=|\?$/

  column = column_for_attribute_without_family_span_columns(name)
  unless column
    family = BigRecord::ConnectionAdapters::Column.extract_family(name)
    column = self.columns_hash[family] if family
  end
  column
end

- (Object) simple_columns

Returns the list of columns that are not spanned on a whole family



57
58
59
# File 'lib/big_record/family_span_columns.rb', line 57

def simple_columns
  columns.select{|c|!c.family?}
end