Permalink
Browse files

Allow ClassyEnum to non ActiveRecord db adaptors

  • Loading branch information...
1 parent 16ed8da commit 2b32d38b4eabcbb2ceac056085ae2e92656e9004 @beerlington beerlington committed Aug 2, 2012
Showing with 8 additions and 4 deletions.
  1. +3 −1 lib/classy_enum/active_record.rb
  2. +4 −2 lib/classy_enum/base.rb
  3. +1 −1 lib/classy_enum/version.rb
@@ -55,4 +55,6 @@ def classy_enum_attr(attribute, options={})
end
end
-ActiveRecord::Base.send :extend, ClassyEnum::ActiveRecord
+if defined?(ActiveRecord::Base)
+ ActiveRecord::Base.send :extend, ClassyEnum::ActiveRecord
+end
View
@@ -25,8 +25,10 @@ def inherited(klass)
# This is due to a bug in Rails where it uses the method result as opposed to the
# database value for validation scopes. A fix will be released in Rails 4, but
# this will remain until Rails 3.x is no longer prevalent.
- Arel::Visitors::ToSql.class_eval do
- define_method "visit_#{klass.name.split('::').join('_')}", lambda {|value| quote(value.to_s) }
+ if defined?(Arel::Visitors::ToSql)
+ Arel::Visitors::ToSql.class_eval do
+ define_method "visit_#{klass.name.split('::').join('_')}", lambda {|value| quote(value.to_s) }
+ end
end
# Convert from MyEnumClass::NumberTwo to :number_two
@@ -1,3 +1,3 @@
module ClassyEnum
- VERSION = "3.0.0"
+ VERSION = "3.0.1"
end

0 comments on commit 2b32d38

Please sign in to comment.