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 |
# File 'lib/shoulda/matchers/active_record/uniqueness/namespace.rb', line 20 def clear constant.constants.each do |child_constant| constant.__send__(:remove_const, child_constant) 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) 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
26 27 28 |
# File 'lib/shoulda/matchers/active_record/uniqueness/namespace.rb', line 26 def to_s constant.to_s end |