Class: Vidalia::Artifact

Inherits:
Object
  • Object
show all
Defined in:
lib/vidalia/artifact.rb

Direct Known Subclasses

Element, Interface, Object

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}, &block) ⇒ Artifact

Create an Artifact

Initializes a Vidalia::Artifact using the data set in Vidalia::Artifact.define. If such data does not exist, this routine will error out. This ensures that all Artifacts have been predefined.

Options

Takes a hash as input where the current options are:

name

(required) specifies the name of the Interface

parent

(required) specifies the Vidalia::Identifier of the parent object

definition

(optional) specifies the Vidalia::Artifact contained by the artifact’s definition

Example

$$$ Example needed $$$


24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/vidalia/artifact.rb', line 24

def initialize(opts = {},&block)
  o = {
    :name => nil,
    :parent => nil,
    :definition => nil
  }.merge(opts)

  Vidalia::checkvar(o[:name],String,self.class.ancestors,"name")
  @name = o[:name]
  @type = Vidalia::Artifact unless @type
  @children = Hash.new

  if o[:parent]
    # Add myself as a child of my parent
    Vidalia::checkvar(o[:parent],Vidalia::Artifact,self.class.ancestors,"parent")
    @parent = o[:parent]
    @parent.add_child(self)
  else
    # Just kidding.  I'm an orphan.  :(
    @parent = nil
  end

  @source_artifact = o[:definition]

  if @source_artifact
    # If this is an instantiation of a definition

    Vidalia::checkvar(@source_artifact,Vidalia::Artifact,self.class.ancestors,"definition")

    # Copy the initialization block and run it if defined
    @init_block = @source_artifact.init_block
    if @init_block
      block = @init_block
      instance_eval(&block)
    end
  else
    # If this is only a definition

    # Store the initialization block
    @init_block = block
  end
end

Instance Attribute Details

#init_blockObject (readonly)

Returns the value of attribute init_block.



5
6
7
# File 'lib/vidalia/artifact.rb', line 5

def init_block
  @init_block
end

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/vidalia/artifact.rb', line 5

def name
  @name
end

#parentObject (readonly)

Returns the value of attribute parent.



5
6
7
# File 'lib/vidalia/artifact.rb', line 5

def parent
  @parent
end

Class Method Details

.copy_from(source) ⇒ Object

Copy an Artifact from another Artifact

Options

Takes one parameter:

source

specifies the name of the Interface to copy from

Example

$$$ Example Needed $$$


79
80
81
82
83
84
85
# File 'lib/vidalia/artifact.rb', line 79

def self.copy_from(source)
  Vidalia::checkvar(source,Vidalia::Artifact,self.class.ancestors,"source")
  @name = source.type
  @type = source.type
  @init_block = source.init_block
  super
end

Instance Method Details

#add_child(object) ⇒ Object

Add a child object to this Artifact

Options

This method takes one parameter:

object

specifies a Vidalia::Artifact object to be added as a child

Example

# Note that both the "Blog API" and "Blog Post" Artifacts must be predefined
blog_api = Vidalia::Artifact.new("Blog API")
blog_post = Vidalia::Artifact.new("Blog Post")
blog_api.add_child(blog_post)


102
103
104
105
106
# File 'lib/vidalia/artifact.rb', line 102

def add_child(object)
  Vidalia::checkvar(object,Vidalia::Artifact,self.class.ancestors,"object")
  @children[object.name] = object
  object.set_parent(self)
end

#get_child(name) ⇒ Object

Get a child of this Artifact

Options

This method takes one parameter:

name

specifies the name of a child of this Artifact

Example

$$$ Example needed $$$


120
121
122
123
# File 'lib/vidalia/artifact.rb', line 120

def get_child(name)
  Vidalia::checkvar(name,String,self.class.ancestors,"name")
  @children[name]
end

#number_of_childrenObject

Get a the number of children of this Artifact

Options

This method takes no parameters.

Example

$$$ Example needed $$$


136
137
138
# File 'lib/vidalia/artifact.rb', line 136

def number_of_children
  @children.size
end

#set_parent(parent) ⇒ Object

Set the parent of this Artifact

Options

This method takes one parameter: parent: specifies the parent object of this Artifact

Example

$$$ Example needed $$$


152
153
154
# File 'lib/vidalia/artifact.rb', line 152

def set_parent(parent)
  @parent = parent
end