Class: Mongoid::Bolt

Inherits:
Object
  • Object
show all
Includes:
Document, Timestamps
Defined in:
lib/mongoid-bolt.rb,
lib/mongoid-bolt.rb

Defined Under Namespace

Modules: Ability Classes: Error

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.abilityObject



295
296
297
# File 'lib/mongoid-bolt.rb', line 295

def Bolt.ability
  Ability
end

.dependenciesObject



14
15
16
17
18
# File 'lib/mongoid-bolt.rb', line 14

def dependencies
  {
    'mongoid'         => [ 'mongoid'         , ' >= 3.0.1' ] ,
  }
end

.for(name, options = {}, &block) ⇒ Object



310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
# File 'lib/mongoid-bolt.rb', line 310

def Bolt.for(name, options = {}, &block)
  name = name.to_s
  conditions = {:name => name}

  attributes = conditions.dup
  attributes[:created_at] || attributes[:updated_at] = Time.now.utc

  lock =
    begin
      where(conditions).first or create!(attributes)
    rescue Object => e
      sleep(rand)
      where(conditions).first or create!(attributes)
    end

  block ? lock.lock(options, &block) : lock
end

.hostnameObject



339
340
341
# File 'lib/mongoid-bolt.rb', line 339

def Bolt.hostname
  @hostname ||= Socket.gethostname
end

.identifierObject



355
356
357
# File 'lib/mongoid-bolt.rb', line 355

def Bolt.identifier
  {:hostname => hostname, :ppid => ppid, :pid => pid, :tid => tid}
end

.libdir(*args, &block) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/mongoid-bolt.rb', line 20

def libdir(*args, &block)
  @libdir ||= File.expand_path(__FILE__).sub(/\.rb$/,'')
  args.empty? ? @libdir : File.join(@libdir, *args)
ensure
  if block
    begin
      $LOAD_PATH.unshift(@libdir)
      block.call()
    ensure
      $LOAD_PATH.shift()
    end
  end
end

.load(*libs) ⇒ Object



34
35
36
37
# File 'lib/mongoid-bolt.rb', line 34

def load(*libs)
  libs = libs.join(' ').scan(/[^\s+]+/)
  libdir{ libs.each{|lib| Kernel.load(lib) } }
end

.pidObject



347
348
349
# File 'lib/mongoid-bolt.rb', line 347

def Bolt.pid
  Process.pid
end

.ppidObject



343
344
345
# File 'lib/mongoid-bolt.rb', line 343

def Bolt.ppid
  Process.ppid
end

.process_alive?(*pids) ⇒ Boolean

Returns:

  • (Boolean)


359
360
361
362
363
364
365
366
367
368
# File 'lib/mongoid-bolt.rb', line 359

def Bolt.process_alive?(*pids)
  pids.flatten.compact.all? do |pid|
    begin
      Process.kill(0, Integer(pid))
      true
    rescue Object
      false
    end
  end
end

.thread_alive?(*tids) ⇒ Boolean

Returns:

  • (Boolean)


370
371
372
373
374
# File 'lib/mongoid-bolt.rb', line 370

def Bolt.thread_alive?(*tids)
  tids.flatten.compact.all? do |tid|
    Thread.list.detect{|thread| thread.object_id == tid}
  end
end

.tidObject



351
352
353
# File 'lib/mongoid-bolt.rb', line 351

def Bolt.tid
  Thread.current.object_id
end

.versionObject



10
11
12
# File 'lib/mongoid-bolt.rb', line 10

def version
  const_get :Version
end

Instance Method Details

#nameObject



330
# File 'lib/mongoid-bolt.rb', line 330

field(:name)