Class: Humble::PrimaryKeyColumn

Inherits:
Column
  • Object
show all
Defined in:
lib/humble/column.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Column

#prepare

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

#defaultObject (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

Returns:

  • (Boolean)


41
42
43
# File 'lib/humble/column.rb', line 41

def has_default_value?(item)
  @default == item.id
end

#primary_key?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/humble/column.rb', line 37

def primary_key?
  true
end