class CodeigniterScaffold::Attribute

Attributes

mysql_type[RW]
name[RW]
type[RW]

Public Class Methods

new(argument) click to toggle source
# File lib/codeigniter_scaffold/attribute.rb, line 6
def initialize(argument)
  @name = argument.split(":")[0].downcase
  @type = argument.split(":")[1].downcase
  @mysql_type = find_mysql_type
  validate
end

Private Class Methods

valid_types() click to toggle source
# File lib/codeigniter_scaffold/attribute.rb, line 14
def self.valid_types
  %w(string text integer)
end

Private Instance Methods

find_mysql_type() click to toggle source
# File lib/codeigniter_scaffold/attribute.rb, line 25
def find_mysql_type
  return "VARCHAR(255)" if @type == 'string'
  return "INT" if @type == 'integer'
  "TEXT"
end
validate() click to toggle source
# File lib/codeigniter_scaffold/attribute.rb, line 18
def validate
  unless Attribute.valid_types.include?(@type)
    puts "Attribute #{@type} is not supported. The supported attributes types are: #{Attribute.valid_types.join(", ")}"
    Kernel.exit
  end
end