Sha256: f2b39cc00296b3ca8e038e80537ab6f0564cbe7845b882efa629be590f667f9d

Contents?: true

Size: 724 Bytes

Versions: 6

Compression:

Stored size: 724 Bytes

Contents

module CodeigniterScaffold
  class Attribute

    attr_accessor :name, :type, :mysql_type

    def initialize(argument)
      @name = argument.split(":")[0].downcase
      @type = argument.split(":")[1].downcase
      @mysql_type = find_mysql_type
      validate
    end

    private
    def self.valid_types
      %w(string text integer)
    end

    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

    def find_mysql_type
      return "VARCHAR(255)" if @type == 'string'
      return "INT" if @type == 'integer'
      "TEXT"
    end
  end
end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
codeigniter3-scaffold-1.1.0 lib/codeigniter_scaffold/attribute.rb
codeigniter-scaffold-2.0 lib/codeigniter_scaffold/attribute.rb
codeigniter-scaffold-1.0.0 lib/codeigniter_scaffold/attribute.rb
codeigniter-scaffold-0.0.3 lib/codeigniter_scaffold/attribute.rb
codeigniter-scaffold-0.0.2 lib/codeigniter_scaffold/attribute.rb
codeigniter-scaffold-0.0.1 lib/codeigniter_scaffold/attribute.rb