Class: Hold::Sequel::PropertyMapper::Column
- Inherits:
-
Hold::Sequel::PropertyMapper
- Object
- Hold::Sequel::PropertyMapper
- Hold::Sequel::PropertyMapper::Column
- Defined in:
- lib/hold/sequel/property_mapper/column.rb
Overview
Simplest case: maps the property directly to a column on the corresponding table.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#column_alias ⇒ Object
readonly
Returns the value of attribute column_alias.
-
#column_name ⇒ Object
readonly
Returns the value of attribute column_name.
-
#column_qualified ⇒ Object
readonly
Returns the value of attribute column_qualified.
-
#columns_aliases_and_tables_for_select ⇒ Object
readonly
Returns the value of attribute columns_aliases_and_tables_for_select.
-
#table ⇒ Object
readonly
Returns the value of attribute table.
Attributes inherited from Hold::Sequel::PropertyMapper
#property, #property_name, #repository
Instance Method Summary collapse
- #build_insert_row(entity, table, row, id = nil) ⇒ Object (also: #build_update_row)
-
#initialize(repo, property_name, options) ⇒ Column
constructor
A new instance of Column.
- #load_value(row, id = nil, version = nil) ⇒ Object
-
#make_filter(value, columns_mapped_to = nil) ⇒ Object
for now ignoring the columns_mapped_to, since Identity mapper is the only one for which this matters at present.
- #make_multi_filter(values, columns_mapped_to = nil) ⇒ Object
Methods inherited from Hold::Sequel::PropertyMapper
#load_values, #post_delete, #post_insert, #post_update, #pre_delete, #pre_insert, #pre_update, setter_dependencies_for
Constructor Details
#initialize(repo, property_name, options) ⇒ Column
Returns a new instance of Column.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/hold/sequel/property_mapper/column.rb', line 6 def initialize(repo, property_name, ) super(repo, property_name) @table = [:table] || @repository.main_table @column_name = ([:column_name] || property_name).to_sym @column_alias = :"#{@table}_#{@column_name}" @column_qualified = Sequel::SQL::QualifiedIdentifier.new(@table, @column_name) @columns_aliases_and_tables_for_select = [ [@column_qualified], [Sequel::SQL::AliasedExpression.new(@column_qualified, @column_alias)], [@table] ] end |
Instance Attribute Details
#column_alias ⇒ Object (readonly)
Returns the value of attribute column_alias.
4 5 6 |
# File 'lib/hold/sequel/property_mapper/column.rb', line 4 def column_alias @column_alias end |
#column_name ⇒ Object (readonly)
Returns the value of attribute column_name.
4 5 6 |
# File 'lib/hold/sequel/property_mapper/column.rb', line 4 def column_name @column_name end |
#column_qualified ⇒ Object (readonly)
Returns the value of attribute column_qualified.
4 5 6 |
# File 'lib/hold/sequel/property_mapper/column.rb', line 4 def column_qualified @column_qualified end |
#columns_aliases_and_tables_for_select ⇒ Object (readonly)
Returns the value of attribute columns_aliases_and_tables_for_select.
4 5 6 |
# File 'lib/hold/sequel/property_mapper/column.rb', line 4 def columns_aliases_and_tables_for_select @columns_aliases_and_tables_for_select end |
#table ⇒ Object (readonly)
Returns the value of attribute table.
4 5 6 |
# File 'lib/hold/sequel/property_mapper/column.rb', line 4 def table @table end |
Instance Method Details
#build_insert_row(entity, table, row, id = nil) ⇒ Object Also known as: build_update_row
25 26 27 |
# File 'lib/hold/sequel/property_mapper/column.rb', line 25 def build_insert_row(entity, table, row, id=nil) row[@column_name] = entity[@property_name] if @table == table && entity.has_key?(@property_name) end |
#load_value(row, id = nil, version = nil) ⇒ Object
21 22 23 |
# File 'lib/hold/sequel/property_mapper/column.rb', line 21 def load_value(row, id=nil, version=nil) row[@column_alias] end |
#make_filter(value, columns_mapped_to = nil) ⇒ Object
for now ignoring the columns_mapped_to, since Identity mapper is the only one for which this matters at present
34 35 36 |
# File 'lib/hold/sequel/property_mapper/column.rb', line 34 def make_filter(value, columns_mapped_to=nil) {@column_qualified => value} end |
#make_multi_filter(values, columns_mapped_to = nil) ⇒ Object
38 39 40 |
# File 'lib/hold/sequel/property_mapper/column.rb', line 38 def make_multi_filter(values, columns_mapped_to=nil) {@column_qualified => values} end |