Class: Agent

Inherits:
Object
  • Object
show all
Includes:
DataMapper::Resource
Defined in:
lib/swarm/agent.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(string_or_attrs) ⇒ Agent

Initialize with string_or_attrs.



32
33
34
35
36
# File 'lib/swarm/agent.rb', line 32

def initialize string_or_attrs
  self.attributes = String === string_or_attrs ?
    { :string => string_or_attrs } :
      string_or_attrs 
end

Class Method Details

.availableObject

Unique available agents.



74
75
76
# File 'lib/swarm/agent.rb', line 74

def self.available
  unique.delete_if { |agent| agent.busy? }
end

.uniqueObject

Unique agents.



64
65
66
67
68
69
# File 'lib/swarm/agent.rb', line 64

def self.unique
  all.inject [] do |agents, agent|
    agents << agent unless agents.include? agent
    agents
  end
end

Instance Method Details

#==(other) ⇒ Object

Check if other equals self. Supports DataMapper join support when checking AgentJob equality, as well as against other Agent instances via their #string value.



44
45
46
47
48
# File 'lib/swarm/agent.rb', line 44

def == other
  AgentJob === other ?
    id == other.agent_id :
      super
end

#busy?Boolean

Check if the agent is busy.

Returns:

  • (Boolean)


53
54
55
# File 'lib/swarm/agent.rb', line 53

def busy?
  busy
end