Module: DataMapper::Is::Entity

Defined in:
lib/dm-appengine/is_entity.rb

Defined Under Namespace

Modules: ClassMethods, Transaction

Constant Summary collapse

DEFAULT_ENTITY_OPTIONS =
{
  :transaction => true,
  :key => :id,
  :parent => :parent,
  :ancestor => :ancestor,
  :descendants => :descendants
}.freeze

Instance Method Summary collapse

Instance Method Details

#is_entity(options = {}) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/dm-appengine/is_entity.rb', line 28

def is_entity(options={})
  extend(ClassMethods)
  
  options = DEFAULT_ENTITY_OPTIONS.merge(options)
  
  # Override the builtin transactions
  if options[:transaction]
    include Transaction; extend Transaction
  end
  
  # Pass :key_name => false if you don't want a key
  if (key_name = options[:key])
    primary_key(key_name)
  end
  
  if (parent_name = options[:parent])
    parent_property(parent_name)
  end
  
  if (ancestor_name = options[:ancestor])
    ancestor_property(ancestor_name)
  end
  
  if (descendants_name = options[:descendants])
    descendants_property(descendants_name)
  end
end