Class: Machinist::DataMapper::Blueprint

Inherits:
Blueprint
  • Object
show all
Defined in:
lib/machinist/data_mapper/blueprint.rb

Instance Method Summary collapse

Instance Method Details

#box(object) ⇒ Object

Box an object for storage in the warehouse.



13
14
15
# File 'lib/machinist/data_mapper/blueprint.rb', line 13

def box(object)
  object.key
end

#lathe_classObject

:nodoc:



35
36
37
# File 'lib/machinist/data_mapper/blueprint.rb', line 35

def lathe_class #:nodoc:
  Machinist::DataMapper::Lathe
end

#make!(attributes = {}) ⇒ Object

Make and save an object.



5
6
7
8
9
10
# File 'lib/machinist/data_mapper/blueprint.rb', line 5

def make!(attributes = {})
  object = make(attributes)
  object.raise_on_save_failure = true
  object.save
  object.reload
end

#outside_transactionObject

Execute a block on a separate database connection, so that any database operations happen outside any open transactions.



24
25
26
27
28
29
30
31
32
33
# File 'lib/machinist/data_mapper/blueprint.rb', line 24

def outside_transaction
  # ActiveRecord manages connections per-thread, so the only way to
  # convince it to open another connection is to start another thread.
  thread = Thread.new do
    begin
      yield
    end
  end
  thread.value
end

#unbox(id) ⇒ Object

Unbox an object from the warehouse.



18
19
20
# File 'lib/machinist/data_mapper/blueprint.rb', line 18

def unbox(id)
  @klass.find(id)
end