Class: ActiveRecord::Has::SparseAttributes::TableStorageConfig
- Inherits:
-
StorageConfig
- Object
- StorageConfig
- ActiveRecord::Has::SparseAttributes::TableStorageConfig
- Defined in:
- lib/active_record/has/sparse_attributes/table_storage.rb
Instance Attribute Summary collapse
-
#attribute_model ⇒ Object
Returns the value of attribute attribute_model.
-
#id_column ⇒ Object
Returns the value of attribute id_column.
Attributes inherited from StorageConfig
#model_class, #serialize_values
Instance Method Summary collapse
-
#initialize(klass, options = {}) ⇒ TableStorageConfig
constructor
A new instance of TableStorageConfig.
- #instance(record) ⇒ Object
Constructor Details
#initialize(klass, options = {}) ⇒ TableStorageConfig
Returns a new instance of TableStorageConfig.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/active_record/has/sparse_attributes/table_storage.rb', line 9 def initialize(klass, = {}) super [:attribute_class_name] ||= 'SparseAttribute' [:id_column] ||= @model_class.model_name.singular.to_s + '_id' if ![:table_name].blank? if ActiveRecord::Base.methods.include?(:set_table_name) table_name = ('set_table_name "' + [:table_name] + '";') || '' else table_name = 'self.table_name = "' + [:table_name] + '";' end else table_name = '' end @id_column = [:id_column] klass.class_eval "class #{options[:attribute_class_name]} < ActiveRecord::Base; #{table_name} validates_presence_of :#{@id_column}, :name; end" @attribute_model = eval("klass::#{options[:attribute_class_name]}") end |
Instance Attribute Details
#attribute_model ⇒ Object
Returns the value of attribute attribute_model.
6 7 8 |
# File 'lib/active_record/has/sparse_attributes/table_storage.rb', line 6 def attribute_model @attribute_model end |
#id_column ⇒ Object
Returns the value of attribute id_column.
7 8 9 |
# File 'lib/active_record/has/sparse_attributes/table_storage.rb', line 7 def id_column @id_column end |
Instance Method Details
#instance(record) ⇒ Object
27 28 29 |
# File 'lib/active_record/has/sparse_attributes/table_storage.rb', line 27 def instance(record) TableStorage.new(record, self) end |