Module: DataMapper::Model

Module | DataMapper::Model
In: | lib/dm-sweatshop/model.rb

Methods added to this module are available on classes that include DataMapper::Resource.

This lets you use Person.pick(:michael) instead of DataMapper::Sweatshop.pick(Person, :michael)

### Methods

default_fauxture_name fix fixture gen gen! gen_attrs generate generate! generate_attributes make pick

### Public Instance methods

default_fauxture_name()

Default fauxture name. Usually :default.

@returns [Symbol] default fauxture name @api public

fix(name = default_fauxture_name, &blk)

Alias for fixture

fixture(name = default_fauxture_name, &blk)

Adds a fixture to record map. Block is supposed to return a hash of attributes.

@param name [Symbol, String] Name of the fixture @param blk [Proc] A proc that returns fixture attributes

@returns nil

@api public

gen(name = default_fauxture_name, attributes = {})

Alias for generate

gen!(name = default_fauxture_name, attributes = {})

Alias for generate!

gen_attrs(name = default_fauxture_name)

Alias for generate_attributes

generate(name = default_fauxture_name, attributes = {})

Creates an instance from hash of attributes, saves it and adds it to the record map. Attributes given as the second argument are merged into attributes from fixture.

If record is valid because of duplicated property value, this method does a retry.

@param name [Symbol] @param attributes [Hash]

@api public

@returns [DataMapper::Resource] added instance

generate!(name = default_fauxture_name, attributes = {})

Same as generate except that it uses Model#create!. It forces invalid objects to be saved in the repository.

@param name [Symbol] @param attributes [Hash]

@api public

@returns [DataMapper::Resource] added instance

generate_attributes(name = default_fauxture_name)

Returns a Hash of attributes from the model map.

@param name [Symbol] name of the fauxture to use

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

@api public

make(name = default_fauxture_name, attributes = {})

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

@param name [Symbol] name of the fauxture to use @param attributes [Hash]

@api private

@returns [DataMapper::Resource] added instance

pick(name = default_fauxture_name)

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

@param name [Symbol] name of the fauxture to pick

@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 public

[Validate]