Class: Swarm

Inherits:
Sinatra::Base
  • Object
show all
Defined in:
lib/swarm/swarm.rb

Constant Summary collapse

VERSION =

– Constants ++

'0.0.1'

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.agents_for(*names) ⇒ Object

Return array of agent instances for names.



173
174
175
176
177
178
179
180
181
182
183
# File 'lib/swarm/swarm.rb', line 173

def self.agents_for *names
  unless names.empty?
    Agent.available.select do |agent|
      names.any? do |name|
        agent.name.to_s.downcase == name.to_s.downcase if agent.name
      end
    end
  else
    Agent.available
  end
end

Instance Method Details

#addressObject

Remote address.



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

def address
  env['REMOTE_ADDR']
end

#json(object) ⇒ Object

Halts with status of 200 and JSON object. Sets content type to application/json and jsonifies the object.



38
39
40
41
42
# File 'lib/swarm/swarm.rb', line 38

def json object
  content_type :json
  object[:status] ||= 1 if object.is_a? Hash
  halt 200, object.to_json
end

#log(string) ⇒ Object

Log string to stderr.



30
31
32
# File 'lib/swarm/swarm.rb', line 30

def log string
  $stderr.puts string
end

#public_path_for(file) ⇒ Object

Path to public file.



61
62
63
# File 'lib/swarm/swarm.rb', line 61

def public_path_for file
  File.dirname(__FILE__) + '/../public/' + file
end

#user_agentObject

User agent.



47
48
49
# File 'lib/swarm/swarm.rb', line 47

def user_agent
  env['HTTP_USER_AGENT']
end