Module DataMapper::Resource
In: lib/dm-core/resource.rb
lib/dm-core/types.rb

Methods

Included Modules

Assertions Transaction Types

Classes and Modules

Module DataMapper::Resource::Transaction

External Aliases

class -> model

Attributes

collection  [W]  +————— Instance methods

Public Class methods

 Appends a module for inclusion into the model class after
 DataMapper::Resource.

 This is a useful way to extend DataMapper::Resource while still retaining
 a self.included method.

 @param [Module] inclusion the module that is to be appended to the module
   after DataMapper::Resource

 @return [TrueClass, FalseClass] whether or not the inclusions have been
   successfully appended to the list
 @return <TrueClass, FalseClass>

-

 @api public

Return all classes that include the DataMapper::Resource module

Returns

Set:a set containing the including classes

Example

  Class Foo
    include DataMapper::Resource
  end

  DataMapper::Resource.descendants.to_a.first == Foo

- @api semipublic

When Resource is included in a class this method makes sure it gets all the methods

- @api private

Public Instance methods

==(other)

Alias for eql?

TODO: add docs @api private

Checks if the attribute is dirty

Parameters

name<Symbol>:name of attribute

Returns

True:returns if attribute is dirty

— @api public

returns the value of the attribute. Do not read from instance variables directly, but use this method. This method handels the lazy loading the attribute and returning of defaults if nessesary.

Parameters

name<Symbol>:name attribute to lookup

Returns

<Types>:the value stored at that given attribute, nil if none, and default if necessary

Example

  Class Foo
    include DataMapper::Resource

    property :first_name, String
    property :last_name, String

    def full_name
      "#{attribute_get(:first_name)} #{attribute_get(:last_name)}"
    end

    # using the shorter syntax
    def name_for_address_book
      "#{last_name}, #{first_name}"
    end
  end

- @api semipublic

Checks if the attribute has been loaded

Example

  class Foo
    include DataMapper::Resource
    property :name, String
    property :description, Text, :lazy => false
  end

  Foo.new.attribute_loaded?(:description) # will return false

— @api public

sets the value of the attribute and marks the attribute as dirty if it has been changed so that it may be saved. Do not set from instance variables directly, but use this method. This method handels the lazy loading the property and returning of defaults if nessesary.

Parameters

name<Symbol>:name attribute to set
value<Type>:value to store at that location

Returns

<Types>:the value stored at that given attribute, nil if none, and default if necessary

Example

  Class Foo
    include DataMapper::Resource

    property :first_name, String
    property :last_name, String

    def full_name(name)
      name = name.split(' ')
      attribute_set(:first_name, name[0])
      attribute_set(:last_name, name[1])
    end

    # using the shorter syntax
    def name_from_address_book(name)
      name = name.split(', ')
      first_name = name[1]
      last_name = name[0]
    end
  end

- @api semipublic

all the attributes of the model

Returns

Hash[<Symbol>]:All the (non)-lazy attributes

— @api public

Mass assign of attributes

Parameters

value_hash <Hash[<Symbol>]>::

— @api public

destroy the instance, remove it from the repository

Returns

<True, False>:results of the destruction

— @api public

Checks if the class is dirty

Returns

True:returns if class is dirty

— @api public

Hash of attributes that have been marked dirty

Returns

Hash:attributes that have been marked dirty

— @api private

Compares if its the same object or if attributes are equal

Parameters

other<Object>:Object to compare to

Returns

<True>:the outcome of the comparison as a boolean

- @api public

Computes a hash for the resource

Returns

<Integer>:the hash value of the resource

- @api public

default id method to return the resource id when there is a single key, and the model was defined with a primary key named something other than id

Returns

<Array[Key], Key> key or keys

— @api public

Inspection of the class name and the attributes

Returns

<String>:with the class name, attributes with their values

Example

>> Foo.new

> #<Foo name=nil updated_at=nil created_at=nil id=nil>

- @api public

fetches all the names of the attributes that have been loaded, even if they are lazy but have been called

Returns

Array[<Symbol>]:names of attributes that have been loaded

Example

  class Foo
    include DataMapper::Resource
    property :name, String
    property :description, Text, :lazy => false
  end

  Foo.new.loaded_attributes # returns [:name]

— @api public

Checks if the model has been saved

Returns

True:status if the model is new

— @api public

set of original values of properties

Returns

Hash:original values of properties

— @api public

Reload association and all child association

Returns

self:returns the class itself

— @api public

Reload specific attributes

Parameters

*attributes<Array[<Symbol>]>:name of attribute

Returns

self:returns the class itself

— @api public

Returns

<Repository>:the respository this resource belongs to in the context of a collection OR in the class‘s context

@api public

save the instance to the data-store

Returns

<True, False>:results of the save

@see DataMapper::Repository#save

— public

TODO: add docs

 Updates attributes and saves model

 ==== Parameters
 attributes<Hash> Attributes to be updated
 keys<Symbol, String, Array> keys of Hash to update (others won't be updated)

 ==== Returns
 <TrueClass, FalseClass> if model got saved or not

-

 @api public

Protected Instance methods

Needs to be a protected method so that it is hookable

Needs to be a protected method so that it is hookable

[Validate]