Class: ActsAsTable::Mapper::ForeignKey
- Defined in:
- lib/acts_as_table/mapper.rb
Overview
ActsAsTable mapper object for an instance of the ForeignKey class.
Instance Method Summary collapse
-
#initialize(row_model, column_model_by_key, record_model, method_name, position_or_key = nil, **options) {|foreign_key| ... } ⇒ ActsAsTable::Mapper::ForeignKey
constructor
Returns a new ActsAsTable mapper object an instance of the ForeignKey class.
-
#map(from, **options) ⇒ ActsAsTable::Mapper::ForeignKey
Builds a new instance of the ForeignKeyMap class.
Constructor Details
#initialize(row_model, column_model_by_key, record_model, method_name, position_or_key = nil, **options) {|foreign_key| ... } ⇒ ActsAsTable::Mapper::ForeignKey
Returns a new ActsAsTable mapper object an instance of the ForeignKey class.
61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/acts_as_table/mapper.rb', line 61 def initialize(row_model, column_model_by_key, record_model, method_name, position_or_key = nil, **, &block) .assert_valid_keys(:default, :primary_key) @row_model, @column_model_by_key, @record_model = row_model, column_model_by_key, record_model @foreign_key = @record_model.foreign_keys.build(method_name: method_name, primary_key: [:primary_key] || 'id', default_value: [:default]) do |foreign_key| unless position_or_key.nil? foreign_key.column_model = position_or_key.is_a?(::Symbol) ? @column_model_by_key[position_or_key] : @row_model.column_models[position_or_key - 1] end end super(&block) end |
Instance Method Details
#map(from, **options) ⇒ ActsAsTable::Mapper::ForeignKey
Note:
Target values for regular expressions may refer to capture groups.
Builds a new instance of the ForeignKeyMap class.
90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/acts_as_table/mapper.rb', line 90 def map(from, **) .assert_valid_keys(:to) @foreign_key.foreign_key_maps.build({ source_value: from.is_a?(::Regexp) ? from.source : from.to_s, target_value: [:to].to_s, regexp: from.is_a?(::Regexp), extended: from.is_a?(::Regexp) && ((from. & ::Regexp::EXTENDED) != 0), ignore_case: from.is_a?(::Regexp) && ((from. & ::Regexp::IGNORECASE) != 0), multiline: from.is_a?(::Regexp) && ((from. & ::Regexp::MULTILINE) != 0), }) self end |