Module: DataMapper::Model

### Home Classes Methods

### In Files

- lib/dm-sweatshop/model.rb

### Methods

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

### Files

- LICENSE
- README.rdoc

### Class/Module Index

Quicksearch

- DataMapper
- DataMapper::Model
- DataMapper::Sweatshop
- DataMapper::Sweatshop::ClassAttributes
- DataMapper::Sweatshop::NoFixtureExist
- DataMapper::Sweatshop::Unique
- DataMapper::Sweatshop::Unique::TooManyTriesException
- DataMapper::Sweatshop::UniqueWorker

No matching classes.

# 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
    def default_fauxture_name
      :default
    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
    def fixture(name = default_fauxture_name, &blk)
      Sweatshop.add(self, name, &blk)
    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
    def generate(name = default_fauxture_name, attributes = {})
      name, attributes = default_fauxture_name, name if name.is_a? Hash
      Sweatshop.create(self, name, attributes)
    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
    def generate!(name = default_fauxture_name, attributes = {})
      name, attributes = default_fauxture_name, name if name.is_a? Hash
      Sweatshop.create!(self, name, attributes)
    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
    def generate_attributes(name = default_fauxture_name)
      Sweatshop.attributes(self, name)
    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
    def make(name = default_fauxture_name, attributes = {})
      name, attributes = default_fauxture_name, name if name.is_a? Hash
      Sweatshop.make(self, name, attributes)
    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
    def pick(name = default_fauxture_name)
      Sweatshop.pick(self, name)
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.