Class: SpecTools::Association

Inherits:
Object
  • Object
show all
Extended by:
SpecToolsExtensions
Includes:
SpecToolsExtensions
Defined in:
lib/spectools.rb,
lib/vnmsh.rb

Overview

SpecTools::Association

Represents a Spectrum Association

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from SpecToolsExtensions

call_default_extension, call_extension, method_missing, method_missing

Constructor Details

#initialize(left_model = Model.new, right_model = Model.new, relation = Relation.new) ⇒ Association

Returns a new instance of Association.



411
412
413
414
415
# File 'lib/spectools.rb', line 411

def initialize(left_model = Model.new, right_model = Model.new, relation = Relation.new)
  @left_model = left_model
  @right_model = right_model
  @relation = relation
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class SpecToolsExtensions

Instance Attribute Details

#left_modelObject

The Model on the left hand side of the association



405
406
407
# File 'lib/spectools.rb', line 405

def left_model
  @left_model
end

#relationObject

The Relation used for this association



409
410
411
# File 'lib/spectools.rb', line 409

def relation
  @relation
end

#right_modelObject

The Model on the right hand side of the association



407
408
409
# File 'lib/spectools.rb', line 407

def right_model
  @right_model
end

Class Method Details

.cli_create(relation, left_model, right_model, session = nil) ⇒ Object

Use CLI to create a new Association left_model and right_model may be Model objects or model handles. The relation argument may be a Relation or a valid relation name.



646
647
648
649
# File 'lib/vnmsh.rb', line 646

def self.cli_create(relation,left_model,right_model,session = nil)
  session = VNMSH.get_session(session)
  return session.create_association(relation,left_model,right_model)
end

.cli_destroy(left_model, right_model, relation, session = nil) ⇒ Object

Use CLI to destroy a given association. left_model and right_model may be Model objects or model handles. The relation argument may be a Relation or a valid relation name.



633
634
635
636
# File 'lib/vnmsh.rb', line 633

def self.cli_destroy(left_model,right_model,relation,session=nil)
  session = VNMSH.get_session(session)
  session.destroy_association(relation,left_model,right_model)
end

.parse(line) ⇒ Object

Take a line of CLI show associations output and populate a new Association object



599
600
601
602
603
604
605
606
607
608
# File 'lib/vnmsh.rb', line 599

def self.parse(line)
  assoc = Association.new()
  lmhandle,lmname,rel,rmhandle,rmname = line.chomp.unpack('A12A1025A33A12A1024')
  assoc.left_model.handle = lmhandle
  assoc.left_model.name = lmname
  assoc.relation.name = rel
  assoc.right_model.handle = rmhandle
  assoc.right_model.name = rmname
  return assoc
end

.parse_child(line) ⇒ Object

Take a line of CLI show children output and populate a new Association object



611
612
613
614
615
616
617
618
# File 'lib/vnmsh.rb', line 611

def self.parse_child(line)
  mhandle,mname,mthandle,mtname,rel = line.chomp.unpack('A12A1025A12A17A31')
  mtype = MType.new(mthandle,mtname)
  model = Model.new(mhandle,mname,mtype)
  relation = Relation.new(rel)
  assoc = Association.new(nil,model,relation)
  return assoc
end

.parse_parent(line) ⇒ Object

Take a line of CLI show parents output and populate a new Association object



621
622
623
624
625
626
627
628
# File 'lib/vnmsh.rb', line 621

def self.parse_parent(line)
  mhandle,mname,mthandle,mtname,rel = line.chomp.unpack('A12A1025A12A17A31')
  mtype = MType.new(mthandle,mtname)
  model = Model.new(mhandle,mname,mtype)
  relation = Relation.new(rel)
  assoc = Association.new(model,nil,relation)
  return assoc
end

Instance Method Details

#cli_destroy(session = nil) ⇒ Object

Use CLI to destroy this association.



639
640
641
# File 'lib/vnmsh.rb', line 639

def cli_destroy(session=nil)
  self.class.cli_destroy(left_model,right_model,relation,session)
end