activerecord_enum 0.1.1 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,3 @@
1
1
  module ActiverecordEnum
2
- VERSION = "0.1.1"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -1,52 +1,9 @@
1
1
  require 'active_record'
2
2
  require 'active_record/base'
3
- require 'active_record/connection_adapters/mysql2_adapter'
4
- require 'active_record/connection_adapters/sqlite3_adapter'
5
3
  require 'active_record/connection_adapters/abstract/schema_definitions.rb'
6
4
 
7
- module ActiveRecord
8
- module ConnectionAdapters
9
- existing_class = defined?( Mysql2Adapter ) ? Mysql2Adapter : AbstractMysqlAdapter
10
-
11
- existing_class.class_eval do
12
- def native_database_types_with_enum
13
- native_database_types_without_enum.merge( :enum => { :name => "enum" }, :set => { :name => "set" } )
14
- end
15
- alias_method :native_database_types_without_enum, :native_database_types
16
- alias_method :native_database_types, :native_database_types_with_enum
17
-
18
- def type_to_sql_with_enum type, limit=nil, *args
19
- if type.to_s == "enum" || type.to_s == "set"
20
- "#{type}(#{quoted_comma_list limit})"
21
- else
22
- type_to_sql_without_enum type, limit, *args
23
- end
24
- end
25
- alias_method :type_to_sql_without_enum, :type_to_sql
26
- alias_method :type_to_sql, :type_to_sql_with_enum
27
-
28
- private
29
- def quoted_comma_list list
30
- list.to_a.map{|n| "'#{n}'"}.join(",")
31
- end
32
- end
33
- end
34
- end
35
-
36
- module ActiveRecord
37
- module ConnectionAdapters
38
- class SQLite3Adapter < SQLiteAdapter
39
- def type_to_sql_with_enum type, limit=nil, *args
40
- if type.to_s == "enum" || type.to_s == "set"
41
- type, limit = :string, nil
42
- end
43
- type_to_sql_without_enum type, limit, *args
44
- end
45
- alias_method :type_to_sql_without_enum, :type_to_sql
46
- alias_method :type_to_sql, :type_to_sql_with_enum
47
- end
48
- end
49
- end
5
+ require 'connection_adapters/sqlite3' if defined?( SQLite3 )
6
+ require 'connection_adapters/mysql2' if defined?( Mysql2 )
50
7
 
51
8
  module ActiveRecord
52
9
  module ConnectionAdapters
@@ -0,0 +1,30 @@
1
+ require 'active_record/connection_adapters/mysql2_adapter'
2
+
3
+ module ActiveRecord
4
+ module ConnectionAdapters
5
+ existing_class = defined?( Mysql2Adapter ) ? Mysql2Adapter : AbstractMysqlAdapter
6
+
7
+ existing_class.class_eval do
8
+ def native_database_types_with_enum
9
+ native_database_types_without_enum.merge( :enum => { :name => "enum" }, :set => { :name => "set" } )
10
+ end
11
+ alias_method :native_database_types_without_enum, :native_database_types
12
+ alias_method :native_database_types, :native_database_types_with_enum
13
+
14
+ def type_to_sql_with_enum type, limit=nil, *args
15
+ if type.to_s == "enum" || type.to_s == "set"
16
+ "#{type}(#{quoted_comma_list limit})"
17
+ else
18
+ type_to_sql_without_enum type, limit, *args
19
+ end
20
+ end
21
+ alias_method :type_to_sql_without_enum, :type_to_sql
22
+ alias_method :type_to_sql, :type_to_sql_with_enum
23
+
24
+ private
25
+ def quoted_comma_list list
26
+ list.to_a.map{|n| "'#{n}'"}.join(",")
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,16 @@
1
+ require 'active_record/connection_adapters/sqlite3_adapter'
2
+
3
+ module ActiveRecord
4
+ module ConnectionAdapters
5
+ class SQLite3Adapter < SQLiteAdapter
6
+ def type_to_sql_with_enum type, limit=nil, *args
7
+ if type.to_s == "enum" || type.to_s == "set"
8
+ type, limit = :string, nil
9
+ end
10
+ type_to_sql_without_enum type, limit, *args
11
+ end
12
+ alias_method :type_to_sql_without_enum, :type_to_sql
13
+ alias_method :type_to_sql, :type_to_sql_with_enum
14
+ end
15
+ end
16
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,5 +1,4 @@
1
1
  require 'rspec'
2
- require 'activerecord_enum'
3
2
 
4
3
  def db
5
4
  ENV["DB"] || "mysql"
@@ -37,6 +36,10 @@ def column_props table, column
37
36
  end
38
37
 
39
38
  db_config = YAML::load(IO.read("spec/database.yml"))
39
+
40
+ require db_config[db]["adapter"]
41
+ require 'activerecord_enum'
42
+
40
43
  ActiveRecord::Base.configurations = db_config
41
44
  ActiveRecord::Base.establish_connection db
42
45
  RSpec.configure do |c|
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord_enum
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 23
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 1
9
- - 1
10
- version: 0.1.1
8
+ - 2
9
+ - 0
10
+ version: 0.2.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Ian Young
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-04-06 00:00:00 Z
18
+ date: 2012-04-17 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  requirement: &id001 !ruby/object:Gem::Requirement
@@ -127,6 +127,8 @@ files:
127
127
  - activerecord_enum.gemspec
128
128
  - lib/activerecord_enum.rb
129
129
  - lib/activerecord_enum/version.rb
130
+ - lib/connection_adapters/mysql2.rb
131
+ - lib/connection_adapters/sqlite3.rb
130
132
  - spec/.travis.database.yml
131
133
  - spec/Gemfile.rails_3_0
132
134
  - spec/Gemfile.rails_3_1