Skip to content
Browse files

Merge pull request #176 from cored/170-extended-modules-const-missing

Fix problem with Virtus extend module (fixes #170)
  • Loading branch information...
2 parents b9af80a + 51edf95 commit 026455b07d91ebd94fb502603095a22868aa1a6e @solnic committed
View
1 lib/virtus.rb
@@ -136,6 +136,7 @@ def self.configuration
require 'virtus/support/equalizer'
require 'virtus/extensions'
+require 'virtus/const_missing_extensions'
require 'virtus/class_inclusions'
require 'virtus/module_extensions'
View
12 lib/virtus/class_methods.rb
@@ -3,6 +3,7 @@ module Virtus
# Class methods that are added when you include Virtus
module ClassMethods
include Extensions
+ include ConstMissingExtensions
# Hook called when module is extended
#
@@ -56,17 +57,6 @@ def attributes
attribute_set
end
- # Hooks into const missing process to determine types of attributes
- #
- # @param [String] name
- #
- # @return [Class]
- #
- # @api private
- def const_missing(name)
- Attribute.determine_type(name) or super
- end
-
private
# Setup descendants' own Attribute-accessor-method-hosting modules
View
16 lib/virtus/const_missing_extensions.rb
@@ -0,0 +1,16 @@
+module Virtus
+ module ConstMissingExtensions
+
+ # Hooks into const missing process to determine types of attributes
+ #
+ # @param [String] name
+ #
+ # @return [Class]
+ #
+ # @api private
+ def const_missing(name)
+ Attribute.determine_type(name) or super
+ end
+
+ end
+end
View
1 lib/virtus/module_extensions.rb
@@ -3,6 +3,7 @@ module Virtus
# Virtus module that can define attributes for later inclusion
#
module ModuleExtensions
+ include ConstMissingExtensions
# Define an attribute in the module
#
View
2 spec/integration/using_modules_spec.rb
@@ -11,6 +11,7 @@ module Name
include Common
attribute :name, String
+ attribute :gamer, Boolean
end
module Age
@@ -33,6 +34,7 @@ class Moderator; end
specify 'including a module with attributes into a class' do
Examples::User.attribute_set[:name].should be_instance_of(Virtus::Attribute::String)
+ Examples::User.attribute_set[:gamer].should be_instance_of(Virtus::Attribute::Boolean)
Examples::Admin.attribute_set[:name].should be_instance_of(Virtus::Attribute::String)
Examples::Admin.attribute_set[:age].should be_instance_of(Virtus::Attribute::Integer)

0 comments on commit 026455b

Please sign in to comment.
Something went wrong with that request. Please try again.