Class: Vidalia::InterfaceDefinition
- Inherits:
-
Object
- Object
- Vidalia::InterfaceDefinition
- Defined in:
- lib/vidalia/dsl.rb,
lib/vidalia/interface_definition.rb
Constant Summary collapse
- @@interfaces =
[]
Instance Attribute Summary collapse
-
#interface ⇒ Object
readonly
Returns the value of attribute interface.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
Class Method Summary collapse
-
.find(name) ⇒ Object
Find an Interface by name.
Instance Method Summary collapse
-
#init(&block) ⇒ Object
Set’s the interface’s init block.
-
#initialize(opts = {}, &block) ⇒ InterfaceDefinition
constructor
Create an Interface Definition.
- #object(name, &block) ⇒ Object
Constructor Details
#initialize(opts = {}, &block) ⇒ InterfaceDefinition
Create an Interface Definition
Under the covers, the InterfaceDefinition will create or find the associated Interface definition. Any instantiated Interface will be copied from this master copy.
Options
Takes two parameters: Takes a hash as input where the current options are:
name
-
(required) specifies the name of the Interface
Takes a block to be executed at initialization time
Example
blog_api = Vidalia::InterfaceDefinition.new("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']
}
30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/vidalia/interface_definition.rb', line 30 def initialize(opts = {}, &block) o = { :name => nil }.merge(opts) Vidalia::checkvar(o[:name],String,self.class.ancestors,"name") # It's OK to "define" an Interface that has already been defined unless @interface = Vidalia::InterfaceDefinition.find(o[:name]) @interface = Vidalia::Interface.new(opts,&block) @@interfaces << @interface end end |
Instance Attribute Details
#interface ⇒ Object (readonly)
Returns the value of attribute interface.
6 7 8 |
# File 'lib/vidalia/interface_definition.rb', line 6 def interface @interface end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/vidalia/interface_definition.rb', line 6 def name @name end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
6 7 8 |
# File 'lib/vidalia/interface_definition.rb', line 6 def parent @parent end |
Class Method Details
.find(name) ⇒ Object
Find an Interface by name
Options
Takes one parameter:
name
-
(required) specifies the name of the Interface
Example
$$$ Example needed $$$
56 57 58 59 60 61 62 63 64 65 |
# File 'lib/vidalia/interface_definition.rb', line 56 def self.find(name) Vidalia::checkvar(name,String,self.class.ancestors,"name") interface = nil @@interfaces.each do |i| if i.name == name interface = i end end interface end |
Instance Method Details
#init(&block) ⇒ Object
Set’s the interface’s init block
26 27 28 |
# File 'lib/vidalia/dsl.rb', line 26 def init(&block) @interface.init_block = block end |
#object(name, &block) ⇒ Object
30 31 32 33 34 |
# File 'lib/vidalia/dsl.rb', line 30 def object(name, &block) obj_def = Vidalia::ObjectDefinition.new(name: name, parent: self) obj_def.instance_eval &block if block obj_def.object end |