Class: EnumTable::SchemaStatements::Table
- Inherits:
- 
      Object
      
        - Object
- EnumTable::SchemaStatements::Table
 
- Defined in:
- lib/enum_table/schema_statements.rb
Instance Method Summary collapse
- #add(value, id = nil) ⇒ Object
- 
  
    
      #initialize(connection, name, max_id = nil)  ⇒ Table 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    A new instance of Table. 
- #remove(value) ⇒ Object
Constructor Details
#initialize(connection, name, max_id = nil) ⇒ Table
Returns a new instance of Table.
| 67 68 69 70 71 | # File 'lib/enum_table/schema_statements.rb', line 67 def initialize(connection, name, max_id=nil) @connection = connection @name = name @max_id = @connection.execute("SELECT max(id) FROM #{@connection.quote_table_name @name}").to_a[0][0] || 0 end | 
Instance Method Details
#add(value, id = nil) ⇒ Object
| 73 74 75 76 77 | # File 'lib/enum_table/schema_statements.rb', line 73 def add(value, id=nil) id ||= @max_id + 1 @max_id = id if id > @max_id @connection.execute "INSERT INTO #{@connection.quote_table_name @name}(id, value) VALUES(#{id}, #{@connection.quote value})" end | 
#remove(value) ⇒ Object
| 79 80 81 | # File 'lib/enum_table/schema_statements.rb', line 79 def remove(value) @connection.execute "DELETE FROM #{@connection.quote_table_name @name} WHERE value = #{@connection.quote value}" end |