Class: Taskinator::Persistence::XmlSerializationVisitor
- Inherits:
-
Visitor::Base
- Object
- Visitor::Base
- Taskinator::Persistence::XmlSerializationVisitor
- Defined in:
- lib/taskinator/persistence.rb
Instance Attribute Summary collapse
-
#builder ⇒ Object
readonly
the redis connection is passed in since it is in the multi statement mode in order to produce one roundtrip to the redis server.
-
#instance ⇒ Object
readonly
Returns the value of attribute instance.
Instance Method Summary collapse
- #incr_task_count ⇒ Object
-
#initialize(builder, instance, base_visitor = self) ⇒ XmlSerializationVisitor
constructor
A new instance of XmlSerializationVisitor.
- #task_count ⇒ Object
-
#visit ⇒ Object
the starting point for serializing the instance.
- #visit_args(attribute) ⇒ Object
- #visit_attribute(attribute) ⇒ Object
- #visit_attribute_enum(attribute, type) ⇒ Object
- #visit_attribute_time(attribute) ⇒ Object
- #visit_process(attribute) ⇒ Object
- #visit_process_reference(attribute) ⇒ Object
- #visit_task_reference(attribute) ⇒ Object
- #visit_tasks(tasks) ⇒ Object
- #visit_type(attribute) ⇒ Object
Constructor Details
#initialize(builder, instance, base_visitor = self) ⇒ XmlSerializationVisitor
Returns a new instance of XmlSerializationVisitor.
352 353 354 355 356 357 358 359 |
# File 'lib/taskinator/persistence.rb', line 352 def initialize(builder, instance, base_visitor=self) @builder = builder @instance = instance @key = instance.key @root = base_visitor.instance @base_visitor = base_visitor @task_count = 0 end |
Instance Attribute Details
#builder ⇒ Object (readonly)
the redis connection is passed in since it is in the multi statement mode in order to produce one roundtrip to the redis server
349 350 351 |
# File 'lib/taskinator/persistence.rb', line 349 def builder @builder end |
#instance ⇒ Object (readonly)
Returns the value of attribute instance.
350 351 352 |
# File 'lib/taskinator/persistence.rb', line 350 def instance @instance end |
Instance Method Details
#incr_task_count ⇒ Object
448 449 450 |
# File 'lib/taskinator/persistence.rb', line 448 def incr_task_count @task_count += 1 end |
#task_count ⇒ Object
444 445 446 |
# File 'lib/taskinator/persistence.rb', line 444 def task_count @task_count end |
#visit ⇒ Object
the starting point for serializing the instance
362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 |
# File 'lib/taskinator/persistence.rb', line 362 def visit @attributes = [] @attributes << [:type, @instance.class.name] @attributes << [:process_uuid, @root.uuid] @attributes << [:state, :initial] @instance.accept(self) @attributes << [:task_count, @task_count] @attributes.each do |(name, value)| builder.tag!('attribute', name => value) end self end |
#visit_args(attribute) ⇒ Object
432 433 434 435 436 437 438 439 440 441 442 |
# File 'lib/taskinator/persistence.rb', line 432 def visit_args(attribute) values = @instance.send(attribute) yaml = Taskinator::Persistence.serialize(values) # greater than 2 MB? if (yaml.bytesize / (1024.0**2)) > 2 Taskinator.logger.warn("Large argument data detected for '#{self.to_s}'. Consider using intrinsic types instead, or try to reduce the amount of data provided.") end @attributes << [attribute, yaml] end |
#visit_attribute(attribute) ⇒ Object
404 405 406 407 |
# File 'lib/taskinator/persistence.rb', line 404 def visit_attribute(attribute) value = @instance.send(attribute) @attributes << [attribute, value] if value end |
#visit_attribute_enum(attribute, type) ⇒ Object
413 414 415 |
# File 'lib/taskinator/persistence.rb', line 413 def visit_attribute_enum(attribute, type) visit_attribute(attribute) end |
#visit_attribute_time(attribute) ⇒ Object
409 410 411 |
# File 'lib/taskinator/persistence.rb', line 409 def visit_attribute_time(attribute) visit_attribute(attribute) end |
#visit_process(attribute) ⇒ Object
379 380 381 382 383 384 385 386 387 388 |
# File 'lib/taskinator/persistence.rb', line 379 def visit_process(attribute) process = @instance.send(attribute) if process @attributes << [attribute, process.uuid] builder.tag!('process', :key => process.key) do |xml| XmlSerializationVisitor.new(xml, process, @base_visitor).visit end end end |
#visit_process_reference(attribute) ⇒ Object
417 418 419 420 |
# File 'lib/taskinator/persistence.rb', line 417 def visit_process_reference(attribute) process = @instance.send(attribute) @attributes << [attribute, process.uuid] if process end |
#visit_task_reference(attribute) ⇒ Object
422 423 424 425 |
# File 'lib/taskinator/persistence.rb', line 422 def visit_task_reference(attribute) task = @instance.send(attribute) @attributes << [attribute, task.uuid] if task end |
#visit_tasks(tasks) ⇒ Object
390 391 392 393 394 395 396 397 398 399 400 401 402 |
# File 'lib/taskinator/persistence.rb', line 390 def visit_tasks(tasks) builder.tag!('tasks', :count => tasks.count) do |xml| tasks.each do |task| xml.tag!('task', :key => task.key) do |xml2| XmlSerializationVisitor.new(xml2, task, @base_visitor).visit unless task.is_a?(Task::SubProcess) incr_task_count unless self == @base_visitor @base_visitor.incr_task_count end end end end end |
#visit_type(attribute) ⇒ Object
427 428 429 430 |
# File 'lib/taskinator/persistence.rb', line 427 def visit_type(attribute) type = @instance.send(attribute) @attributes << [attribute, type.name] if type end |