Class: Nanite::TagQuery

Inherits:
Packet show all
Defined in:
lib/nanite/packets.rb

Overview

Tag query: retrieve agent ids with associated tags that match given tags

Options: from is sender identity opts Hash of options, two options are supported, at least one must be set:

:tags is an array of tags defining a query that returned agents tags must match
:agent_ids is an array of agents whose tags should be returned

Instance Attribute Summary collapse

Attributes inherited from Packet

#size

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Packet

#id_to_s, #to_json

Constructor Details

#initialize(from, opts, size = nil) ⇒ TagQuery

Returns a new instance of TagQuery.



229
230
231
232
233
234
235
236
# File 'lib/nanite/packets.rb', line 229

def initialize(from, opts, size=nil)
  @from       = from
  @token      = opts[:token]
  @agent_ids  = opts[:agent_ids]
  @tags       = opts[:tags]
  @persistent = opts[:persistent]
  @size       = size
end

Instance Attribute Details

#agent_idsObject

Returns the value of attribute agent_ids.



227
228
229
# File 'lib/nanite/packets.rb', line 227

def agent_ids
  @agent_ids
end

#fromObject

Returns the value of attribute from.



227
228
229
# File 'lib/nanite/packets.rb', line 227

def from
  @from
end

#persistentObject

Returns the value of attribute persistent.



227
228
229
# File 'lib/nanite/packets.rb', line 227

def persistent
  @persistent
end

#tagsObject

Returns the value of attribute tags.



227
228
229
# File 'lib/nanite/packets.rb', line 227

def tags
  @tags
end

#tokenObject

Returns the value of attribute token.



227
228
229
# File 'lib/nanite/packets.rb', line 227

def token
  @token
end

Class Method Details

.json_create(o) ⇒ Object



238
239
240
241
242
243
# File 'lib/nanite/packets.rb', line 238

def self.json_create(o)
  i = o['data']
  new(i['from'], { :token => i['token'], :agent_ids => i['agent_ids'],
                   :tags => i['tags'],   :persistent => i['persistent'] },
                 o['size'])
end

Instance Method Details

#to_s(filter = nil) ⇒ Object



245
246
247
248
249
250
251
# File 'lib/nanite/packets.rb', line 245

def to_s(filter=nil)
  log_msg = "#{super} <#{token}>"
  log_msg += " from #{id_to_s(from)}" if filter.nil? || filter.include?(:from)
  log_msg += " agent_ids #{agent_ids.inspect}" 
  log_msg += " tags: #{tags.inspect}" 
  log_msg
end