Module: ActiveHash::Enum::Methods

Defined in:
lib/enum/enum.rb

Instance Method Summary collapse

Instance Method Details

#delete_allObject



22
23
24
25
26
27
28
29
30
# File 'lib/enum/enum.rb', line 22

def delete_all
  if @enum_accessors.present?
    @records.each do |record|
      constant = constant_for(record, @enum_accessors)
      remove_const(constant) if const_defined?(constant, false)
    end
  end
  super
end

#enum_accessor(*field_names) ⇒ Object



12
13
14
15
# File 'lib/enum/enum.rb', line 12

def enum_accessor(*field_names)
  @enum_accessors = field_names
  reload
end

#insert(record) ⇒ Object



17
18
19
20
# File 'lib/enum/enum.rb', line 17

def insert(record)
  super
  set_constant(record) if defined?(@enum_accessors)
end