class Vidalia::Artifact
Attributes
Public Class Methods
Copy an Artifact
from another Artifact
Options
Takes one parameter:
source
-
specifies the name of the
Interface
to copy from
Example
$$$ Example Needed $$$
# 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
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 $$$
# 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
Public Instance Methods
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)
# 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 a the number of children of this Artifact
Options
This method takes no parameters.
Example
$$$ Example needed $$$
# File lib/vidalia/artifact.rb, line 136 def number_of_children @children.size end