Class: DataMapper::Sweatshop

Class | DataMapper::Sweatshop
In: | lib/dm-sweatshop/sweatshop.rb lib/dm-sweatshop/unique.rb lib/dm-sweatshop/version.rb
Parent: | Object

### Methods

add attributes create create! expand_callable_values make pick record

### Classes and Modules

Module DataMapper::Sweatshop::Unique
Class DataMapper::Sweatshop::NoFixtureExist
Class DataMapper::Sweatshop::UniqueWorker

### Constants

VERSION | = | '0.10.1'.freeze

### Attributes

model_map | [RW] |
record_map | [RW] |

### Public Class methods

add(klass, name, &proc)

Adds a Proc to model map. Proc must return a Hash of attributes.

@param klass [Class, DataMapper::Resource] @param name [Symbol] @param instance [DataMapper::Resource]

@api private

@returns [Array] model map

attributes(klass, name)

Returns a Hash of attributes from the model map

@param klass [Class, DataMapper::Resource] @param name [Symbol]

@returns [Hash] existing instance of a model from the model map @raises NoFixtureExist when requested fixture does not exist in the model map

@api private

create(klass, name, attributes = {})

Creates an instance from given hash of attributes, saves it and adds it to the record map.

@param klass [Class, DataMapper::Resource] @param name [Symbol] @param attributes [Hash]

@api private

@returns [DataMapper::Resource] added instance

create!(klass, name, attributes = {})

Same as create but calls Model#create! and does save invalid models

@param klass [Class, DataMapper::Resource] @param name [Symbol] @param attributes [Hash]

@api private

@returns [DataMapper::Resource] added instance

expand_callable_values(hash)

Returns a Hash with callable values evaluated.

@param hash [Hash]

@returns [Hash] existing instance of a model from the model map

@api private

make(klass, name, attributes = {})

Creates an instance from given hash of attributes and adds it to records map without saving.

@param klass [Class, DataMapper::Resource] @param name [Symbol] @param attributes [Hash]

@api private

@returns [DataMapper::Resource] added instance

pick(klass, name)

Returns a pre existing instance of a model from the record map

@param klass [Class, DataMapper::Resource] @param name [Symbol]

@returns [DataMapper::Resource] existing instance of a model from the record map @raises DataMapper::Sweatshop::NoFixtureExist when requested fixture does not exist in the record map

@api private

record(klass, name, instance)

Adds an instance to records map.

@param klass [Class, DataMapper::Resource] @param name [Symbol] @param instance [DataMapper::Resource]

@api private

@returns [DataMapper::Resource] added instance

[Validate]