Class: ToughGuy::SingletonModel

Inherits:
Model
  • Object
show all
Defined in:
lib/toughguy/singleton_model.rb

Instance Attribute Summary

Attributes inherited from Model

#collection, #values

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Model

#==, #[], [], #[]=, add_index, #after_create, #after_destroy, #after_load, all, #before_create, #before_destroy, #bulk, bulk, collection, collection_name, connection, connection=, count, create, #database, database, database=, #db, db_class_name, db_key, delete, #destroy, destroy_all, #destroyed?, drop, each, ensure_index, #exists?, first, #id, inherited, #initialize, #inspect, limit, load, map, map_keys, mapped_db_classes, #method_missing, #model, #new?, paginate, query, recreate_indexes, #refresh, remove_class_with_db, #save, #set, set_collection, set_collection_name, sort, stats, subclass_with_db, #to_s, to_table_name, #update, update, with_db

Constructor Details

This class inherits a constructor from ToughGuy::Model

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class ToughGuy::Model

Class Method Details

.all_resident_instancesObject



11
12
13
14
15
# File 'lib/toughguy/singleton_model.rb', line 11

def self.all_resident_instances
  list = @subclass_map ?
    @subclass_map.values.map {|c| c.resident_instance}.compact : []
  @instance ? (list << resident_instance) : list
end

.delete_allObject



21
22
23
24
# File 'lib/toughguy/singleton_model.rb', line 21

def self.delete_all
  super
  reset
end

.instanceObject



3
4
5
# File 'lib/toughguy/singleton_model.rb', line 3

def self.instance
  @instance ||= (first || create)
end

.resetObject



17
18
19
# File 'lib/toughguy/singleton_model.rb', line 17

def self.reset
  @instance = nil
end

.resident_instanceObject



7
8
9
# File 'lib/toughguy/singleton_model.rb', line 7

def self.resident_instance
  @instance
end

Instance Method Details

#deleteObject



26
27
28
29
# File 'lib/toughguy/singleton_model.rb', line 26

def delete
  super
  model.reset
end