Class: Shoulda::Matchers::ActiveRecord::Uniqueness::Namespace
- Inherits:
-
Object
- Object
- Shoulda::Matchers::ActiveRecord::Uniqueness::Namespace
- Defined in:
- lib/shoulda/matchers/active_record/uniqueness/namespace.rb
Instance Method Summary collapse
- #clear ⇒ Object
- #has?(name) ⇒ Boolean
-
#initialize(constant) ⇒ Namespace
constructor
A new instance of Namespace.
- #set(name, value) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(constant) ⇒ Namespace
Returns a new instance of Namespace.
8 9 10 |
# File 'lib/shoulda/matchers/active_record/uniqueness/namespace.rb', line 8 def initialize(constant) @constant = constant end |
Instance Method Details
#clear ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/shoulda/matchers/active_record/uniqueness/namespace.rb', line 20 def clear test_model_classes = [] constant.constants.each do |child_constant| child = constant.const_get(child_constant) if defined?(::ActiveRecord::Base) && child.is_a?(Class) && child < ::ActiveRecord::Base test_model_classes << child end constant.remove_const(child_constant) rescue NameError # Constant may have been removed elsewhere; ignore end if defined?(::ActiveSupport::DescendantsTracker) && test_model_classes.any? ::ActiveSupport::DescendantsTracker.clear(test_model_classes) end end |
#has?(name) ⇒ Boolean
12 13 14 |
# File 'lib/shoulda/matchers/active_record/uniqueness/namespace.rb', line 12 def has?(name) constant.const_defined?(name, false) end |
#set(name, value) ⇒ Object
16 17 18 |
# File 'lib/shoulda/matchers/active_record/uniqueness/namespace.rb', line 16 def set(name, value) constant.const_set(name, value) end |
#to_s ⇒ Object
43 44 45 |
# File 'lib/shoulda/matchers/active_record/uniqueness/namespace.rb', line 43 def to_s constant.to_s end |