| Module | DataMapper::Resource |
| In: |
lib/dm-core/resource.rb
lib/dm-core/types.rb |
| class | -> | model |
| collection | [W] | +————— Instance 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
| Set: | a set containing the including classes |
Class Foo
include DataMapper::Resource
end
DataMapper::Resource.descendants.to_a.first == Foo
- @api semipublic
Checks if the attribute is dirty
| name<Symbol>: | name of attribute |
| 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.
| name<Symbol>: | name attribute to lookup |
| <Types>: | the value stored at that given attribute, nil if none, and default if necessary |
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
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.
| name<Symbol>: | name attribute to set |
| value<Type>: | value to store at that location |
| <Types>: | the value stored at that given attribute, nil if none, and default if necessary |
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
destroy the instance, remove it from the repository
| <True, False>: | results of the destruction |
— @api public
Hash of attributes that have been marked dirty
| Hash: | attributes that have been marked dirty |
— @api private
Compares if its the same object or if attributes are equal
| other<Object>: | Object to compare to |
| <True>: | the outcome of the comparison as a boolean |
- @api public
Inspection of the class name and the attributes
| <String>: | with the class name, attributes with their values |
>> Foo.new
- @api public
fetches all the names of the attributes that have been loaded, even if they are lazy but have been called
| Array[<Symbol>]: | names of attributes that have been loaded |
class Foo
include DataMapper::Resource
property :name, String
property :description, Text, :lazy => false
end
Foo.new.loaded_attributes # returns [:name]
— @api public
Reload specific attributes
| *attributes<Array[<Symbol>]>: | name of attribute |
| self: | returns the class itself |
— @api public
| <Repository>: | the respository this resource belongs to in the context of a collection OR in the class‘s context |
@api public
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