Class: Shoulda::Matchers::ActiveRecord::Uniqueness::Namespace

Inherits:
Object
  • Object
show all
Defined in:
lib/shoulda/matchers/active_record/uniqueness/namespace.rb

Instance Method Summary collapse

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

#clearObject



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

Returns:

  • (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_sObject



26
27
28
# File 'lib/shoulda/matchers/active_record/uniqueness/namespace.rb', line 26

def to_s
  constant.to_s
end