enum_column 0.1.2 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
data/enum_column.gemspec CHANGED
@@ -6,12 +6,10 @@ Gem::Specification.new do |s|
6
6
  s.name = "enum_column"
7
7
  s.version = EnumColumn::VERSION
8
8
  s.platform = Gem::Platform::RUBY
9
- s.authors = ["Stephan Kaag"]
9
+ s.authors = ["Stephan Kaag", "Chiel Wester"]
10
10
  s.email = ["stephan.kaag@holder.nl"]
11
- s.homepage = ""
12
11
  s.summary = "Ruby on Rails Enumerated Column Constraints"
13
- s.description = "Ruby on Rails Enumerated Column Constraints. Rails 2 only at the moment."
14
-
12
+ s.description = "This gem enables enum column support for ActiveRecord 2."
15
13
  s.files = `git ls-files`.split("\n")
16
14
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
15
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
data/lib/enum_column.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'enum_column/enum_adapter'
2
2
  require 'enum_column/mysql_adapter' if defined? ActiveRecord::ConnectionAdapters::MysqlAdapter
3
+ require 'enum_column/mysql2_adapter' if defined? ActiveRecord::ConnectionAdapters::Mysql2Adapter
3
4
  require 'enum_column/postgresql_adapter' if defined? ActiveRecord::ConnectionAdapters::PostgreSQLAdapter
4
5
  require 'enum_column/sqlite3_adapter' if defined? ActiveRecord::ConnectionAdapters::SQLite3Adapter
5
6
  require 'enum_column/schema_statements'
@@ -0,0 +1,32 @@
1
+ module ActiveRecord
2
+ module ConnectionAdapters
3
+ class Mysql2Adapter
4
+ alias __native_database_types_enum native_database_types
5
+
6
+ def native_database_types #:nodoc
7
+ types = __native_database_types_enum
8
+ types[:enum] = { :name => "enum" }
9
+ types
10
+ end
11
+
12
+ def columns(table_name, name = nil)#:nodoc:
13
+ sql = "SHOW FIELDS FROM #{table_name}"
14
+ columns = []
15
+ execute(sql, name).each { |field| columns << MysqlColumnWithEnum.new(field[0], field[4], field[1], field[2] == "YES") }
16
+ columns
17
+ end
18
+ end
19
+
20
+ class MysqlColumnWithEnum < Mysql2Column
21
+ include ActiveRecordEnumerations::Column
22
+
23
+ def initialize(name, default, sql_type = nil, null = true)
24
+ if sql_type =~ /^enum/i
25
+ values = sql_type.sub(/^enum\('([^)]+)'\)/i, '\1').split("','").map { |v| v.intern }
26
+ default = default.intern if default and !default.empty?
27
+ end
28
+ super(name, default, sql_type, null, values)
29
+ end
30
+ end
31
+ end
32
+ end
@@ -1,3 +1,3 @@
1
1
  module EnumColumn
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.4"
3
3
  end
metadata CHANGED
@@ -1,16 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: enum_column
3
3
  version: !ruby/object:Gem::Version
4
- hash: 31
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 2
10
- version: 0.1.2
9
+ - 4
10
+ version: 0.1.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Stephan Kaag
14
+ - Chiel Wester
14
15
  autorequire:
15
16
  bindir: bin
16
17
  cert_chain: []
@@ -19,7 +20,7 @@ date: 2011-03-03 00:00:00 +01:00
19
20
  default_executable:
20
21
  dependencies: []
21
22
 
22
- description: Ruby on Rails Enumerated Column Constraints. Rails 2 only at the moment.
23
+ description: This gem enables enum column support for ActiveRecord 2.
23
24
  email:
24
25
  - stephan.kaag@holder.nl
25
26
  executables: []
@@ -36,6 +37,7 @@ files:
36
37
  - lib/enum_column.rb
37
38
  - lib/enum_column/active_record_helper.rb
38
39
  - lib/enum_column/enum_adapter.rb
40
+ - lib/enum_column/mysql2_adapter.rb
39
41
  - lib/enum_column/mysql_adapter.rb
40
42
  - lib/enum_column/postgresql_adapter.rb
41
43
  - lib/enum_column/quoting.rb
@@ -45,7 +47,7 @@ files:
45
47
  - lib/enum_column/validations.rb
46
48
  - lib/enum_column/version.rb
47
49
  has_rdoc: true
48
- homepage: ""
50
+ homepage:
49
51
  licenses: []
50
52
 
51
53
  post_install_message: