Module: DataMapper::Subject

Included in:
Associations::Relationship, Property
Defined in:
lib/dm-core/support/subject.rb

Instance Method Summary collapse

Instance Method Details

#default?Boolean

Returns true if the subject has a default value

Returns:

  • (Boolean)

    true if the subject has a default value



29
30
31
# File 'lib/dm-core/support/subject.rb', line 29

def default?
  @options.key?(:default)
end

#default_for(resource) ⇒ Object

Returns a default value of the subject for given resource

When default value is a callable object, it is called with resource and subject passed as arguments.

Parameters:

  • resource (Resource)

    the model instance for which the default is to be set

Returns:

  • (Object)

    the default value of this subject for resource



15
16
17
18
19
20
21
# File 'lib/dm-core/support/subject.rb', line 15

def default_for(resource)
  if @default.respond_to?(:call)
    @default.call(resource, self)
  else
    DataMapper::Ext.try_dup(@default)
  end
end