Class: Vidalia::Interface

Inherits:
Artifact show all
Defined in:
lib/vidalia/dsl.rb,
lib/vidalia/interface.rb

Instance Attribute Summary collapse

Attributes inherited from Artifact

#parent

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Artifact

#add_child, copy_from, #get_child, #number_of_children, #set_parent

Constructor Details

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

Create an Interface (inherited from Vidalia::Artifact)

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

Options

Takes a hash as input where the current options are:

name

specifies the name of the Interface

Example

blog_api = Vidalia::Interface.new("Blog API")


48
49
50
51
52
53
54
55
56
# File 'lib/vidalia/interface.rb', line 48

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

  @type = Vidalia::Interface 
  super
end

Instance Attribute Details

#init_blockObject

Returns the value of attribute init_block.



13
14
15
# File 'lib/vidalia/dsl.rb', line 13

def init_block
  @init_block
end

#interfaceObject (readonly)

Returns the value of attribute interface.



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

def interface
  @interface
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

Class Method Details

.define(opts = {}, &block) ⇒ Object

Define an Interface

This routine “stores” the defined Interface attributes in a Vidalia::InterfaceDefinition. Any subsequent call to instantiate an Interface object will copy that object from the InterfaceDefinition.

Options

Takes a hash as input where the current options are:

name

(required) specifies the name of the interface

block

(optional) specifies a block of code to be run when the interface object is initialized

Example

Vidalia::Interface.define(:name => "Blog API") {
  @db_password = ENV['BLOG_DB_PASSWORD']
  @db_userid = ENV['BLOG_DB_PASSWORD']
  @db_ip = ENV['BLOG_DB_IP']
  @db_port = ENV['BLOG_DB_PORT']
}


28
29
30
# File 'lib/vidalia/interface.rb', line 28

def self.define(opts = {}, &block)
  Vidalia::InterfaceDefinition.new(opts,&block)
end

.get(name) ⇒ Object

Get an Interface object by name

Options

This method takes one parameter:

name

(required) specifies the name of the Interface

Example

$$$ Example needed $$$


96
97
98
99
100
101
# File 'lib/vidalia/interface.rb', line 96

def self.get(name)
  return Vidalia::Interface.new(
    :name => name,
    :definition => Vidalia::InterfaceDefinition.find(name)
  )
end

Instance Method Details

#object(name) ⇒ Object

Retrieve a child Object of this Interface by name

Options

This method takes one parameter:

name

specifies the name of the child Object

Example

$$$ Example needed $$$


70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/vidalia/interface.rb', line 70

def object(name)
  Vidalia::checkvar(name,String,self.class.ancestors,"name")
  child = get_child(name)
  unless child
    # Child does not yet exist.  Create it.
    child = Vidalia::Object.new(
      :name => name,
      :parent => self,
      :definition => @source_artifact.get_child(name)
    )
  end
  child
end