Class: Humble::PrimaryKeyColumn
Instance Attribute Summary collapse
-
#default ⇒ Object
readonly
Returns the value of attribute default.
Instance Method Summary collapse
- #apply(id, entity) ⇒ Object
- #destroy(connection, entity) ⇒ Object
- #has_default_value?(item) ⇒ Boolean
-
#initialize(name, default) ⇒ PrimaryKeyColumn
constructor
A new instance of PrimaryKeyColumn.
- #primary_key? ⇒ Boolean
Methods inherited from Column
Constructor Details
#initialize(name, default) ⇒ PrimaryKeyColumn
Returns a new instance of PrimaryKeyColumn.
24 25 26 27 |
# File 'lib/humble/column.rb', line 24 def initialize(name, default) super(name) @default = default end |
Instance Attribute Details
#default ⇒ Object (readonly)
Returns the value of attribute default.
22 23 24 |
# File 'lib/humble/column.rb', line 22 def default @default end |
Instance Method Details
#apply(id, entity) ⇒ Object
29 30 31 |
# File 'lib/humble/column.rb', line 29 def apply(id, entity) entity.instance_variable_set("@#{column_name}", id ) end |
#destroy(connection, entity) ⇒ Object
33 34 35 |
# File 'lib/humble/column.rb', line 33 def destroy(connection, entity) connection.where(column_name.to_sym => entity.id).delete end |
#has_default_value?(item) ⇒ Boolean
41 42 43 |
# File 'lib/humble/column.rb', line 41 def has_default_value?(item) @default == item.id end |
#primary_key? ⇒ Boolean
37 38 39 |
# File 'lib/humble/column.rb', line 37 def primary_key? true end |