DataMapper::Model

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)

Public Instance Methods

default_fauxture_name() click to toggle source

Default fauxture name. Usually :default.

@return [Symbol] default fauxture name @api public

     # File lib/dm-sweatshop/model.rb, line 103
103:     def default_fauxture_name
104:       :default
105:     end
fix(name = default_fauxture_name, &blk) click to toggle source
Alias for: fixture
fixture(name = default_fauxture_name, &blk) click to toggle source

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

@return nil

@api public

    # File lib/dm-sweatshop/model.rb, line 17
17:     def fixture(name = default_fauxture_name, &blk)
18:       Sweatshop.add(self, name, &blk)
19:     end
Also aliased as: fix
gen(name = default_fauxture_name, attributes = {}) click to toggle source
Alias for: generate
gen!(name = default_fauxture_name, attributes = {}) click to toggle source
Alias for: generate!
gen_attrs(name = default_fauxture_name) click to toggle source
Alias for: generate_attributes
generate(name = default_fauxture_name, attributes = {}) click to toggle source

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

@return [DataMapper::Resource] added instance

    # File lib/dm-sweatshop/model.rb, line 36
36:     def generate(name = default_fauxture_name, attributes = {})
37:       name, attributes = default_fauxture_name, name if name.is_a? Hash
38:       Sweatshop.create(self, name, attributes)
39:     end
Also aliased as: gen
generate!(name = default_fauxture_name, attributes = {}) click to toggle source

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

@return [DataMapper::Resource] added instance

    # File lib/dm-sweatshop/model.rb, line 52
52:     def generate!(name = default_fauxture_name, attributes = {})
53:       name, attributes = default_fauxture_name, name if name.is_a? Hash
54:       Sweatshop.create!(self, name, attributes)
55:     end
Also aliased as: gen!
generate_attributes(name = default_fauxture_name) click to toggle source

Returns a Hash of attributes from the model map.

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

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

@api public

    # File lib/dm-sweatshop/model.rb, line 67
67:     def generate_attributes(name = default_fauxture_name)
68:       Sweatshop.attributes(self, name)
69:     end
Also aliased as: gen_attrs
make(name = default_fauxture_name, attributes = {}) click to toggle source

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

@return [DataMapper::Resource] added instance

    # File lib/dm-sweatshop/model.rb, line 82
82:     def make(name = default_fauxture_name, attributes = {})
83:       name, attributes = default_fauxture_name, name if name.is_a? Hash
84:       Sweatshop.make(self, name, attributes)
85:     end
pick(name = default_fauxture_name) click to toggle source

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

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

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

@api public

    # File lib/dm-sweatshop/model.rb, line 95
95:     def pick(name = default_fauxture_name)
96:       Sweatshop.pick(self, name)
97:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.