Module: Perpetuity

Defined in:
lib/perpetuity.rb,
lib/perpetuity/config.rb,
lib/perpetuity/mapper.rb,
lib/perpetuity/version.rb,
lib/perpetuity/attribute.rb,
lib/perpetuity/reference.rb,
lib/perpetuity/retrieval.rb,
lib/perpetuity/duplicator.rb,
lib/perpetuity/rails_model.rb,
lib/perpetuity/dereferencer.rb,
lib/perpetuity/identity_map.rb,
lib/perpetuity/attribute_set.rb,
lib/perpetuity/dirty_tracker.rb,
lib/perpetuity/data_injectable.rb,
lib/perpetuity/mapper_registry.rb,
lib/perpetuity/exceptions/duplicate_key_error.rb

Defined Under Namespace

Modules: DataInjectable, RailsModel Classes: Attribute, AttributeSet, Configuration, Dereferencer, DirtyTracker, Duplicator, IdentityMap, Mapper, MapperRegistry, Reference, Retrieval

Constant Summary collapse

VERSION =
"1.0.1"
DuplicateKeyError =
Class.new(StandardError)

Class Method Summary collapse

Class Method Details

.[](klass) ⇒ Object



23
24
25
# File 'lib/perpetuity.rb', line 23

def self.[] klass
  mapper_registry[klass]
end

.configurationObject



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

def self.configuration
  @configuration ||= Configuration.new
end

.configure(&block) ⇒ Object



7
8
9
10
11
# File 'lib/perpetuity.rb', line 7

def self.configure &block
  register_standard_adapters
  detect_rails
  configuration.instance_exec(&block)
end

.data_source(*args) ⇒ Object



31
32
33
# File 'lib/perpetuity.rb', line 31

def self.data_source *args
  configure { data_source *args }
end

.generate_mapper_for(klass, &block) ⇒ Object



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

def self.generate_mapper_for klass, &block
  mapper = Class.new(Mapper)
  mapper.map klass, mapper_registry
  mapper.class_eval(&block) if block_given?
end

.loggerObject



35
36
37
# File 'lib/perpetuity.rb', line 35

def self.logger
  configuration.logger
end

.mapper_registryObject



27
28
29
# File 'lib/perpetuity.rb', line 27

def self.mapper_registry
  @mapper_registry ||= MapperRegistry.new
end

.register_adapter(adapters) ⇒ Object



39
40
41
42
43
44
45
46
47
48
# File 'lib/perpetuity.rb', line 39

def self.register_adapter adapters
  config_adapters = Perpetuity::Configuration.adapters
  adapters.each do |adapter_name, adapter_class|
    if config_adapters.has_key?(adapter_name) && config_adapters[adapter_name] != adapter_class
      raise "That adapter name has already been registered for #{config_adapters[adapter_name]}"
    else
      config_adapters[adapter_name] = adapter_class
    end
  end
end