lib/pg_serializable.rb in pg_serializable-1.4.0 vs lib/pg_serializable.rb in pg_serializable-2.0.0
- old
+ new
@@ -19,10 +19,19 @@
end
module PgSerializable
extend ActiveSupport::Concern
+ def self.validate_traits!
+ ActiveRecord::Base.descendants.each do |klass|
+ begin
+ klass.validate_traits!
+ rescue NoMethodError, ActiveRecord::NoDatabaseError
+ end
+ end
+ end
+
included do
include Visitable
def json(trait: :default)
self.class.to_pg_json accept(PgSerializable::Visitors::Json.new, trait: trait)
@@ -34,13 +43,9 @@
to_pg_json accept(PgSerializable::Visitors::Json.new, trait: trait)
end
def serializable(&blk)
trait_manager.instance_eval &blk
- begin
- validate_traits!
- rescue ActiveRecord::NoDatabaseError
- end
end
def trait_manager
@trait_manager ||= TraitManager.new(self)
end