Class: Vidalia::Element
- Defined in:
- lib/vidalia/dsl.rb,
lib/vidalia/element.rb
Instance Attribute Summary collapse
-
#confirm_function ⇒ Object
readonly
Returns the value of attribute confirm_function.
-
#get_function ⇒ Object
readonly
Returns the value of attribute get_function.
-
#init_block ⇒ Object
Returns the value of attribute init_block.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
-
#retrieve_function ⇒ Object
readonly
Returns the value of attribute retrieve_function.
-
#set_function ⇒ Object
readonly
Returns the value of attribute set_function.
-
#update_function ⇒ Object
readonly
Returns the value of attribute update_function.
-
#verify_function ⇒ Object
readonly
Returns the value of attribute verify_function.
Class Method Summary collapse
-
.copy_from(source) ⇒ Object
Copy an Interface from another Interface (inherited from Vidalia::Artifact).
-
.define(opts = {}, &block) ⇒ Object
Define an Element.
Instance Method Summary collapse
-
#add_confirm(&block) ⇒ Object
Add a “confirm” function.
-
#add_generic_confirm ⇒ Object
Set the generic confirm directive for this Element.
-
#add_generic_retrieve ⇒ Object
Set the generic retrieve directive for this Element.
-
#add_generic_update ⇒ Object
Set the generic update directive for this Element.
-
#add_generic_verify ⇒ Object
Set the generic verify directive for this Element.
-
#add_get(&block) ⇒ Object
Add a “get” function.
-
#add_retrieve(&block) ⇒ Object
Add a “retrieve” function.
-
#add_set(&block) ⇒ Object
Add a “set” function.
-
#add_update(&block) ⇒ Object
Add a “update” function.
-
#add_verify(&block) ⇒ Object
Add a “verify” function.
-
#confirm(inparams = {}) ⇒ Object
Call the “confirm” function.
-
#get(inparams = {}) ⇒ Object
Call the “get” function.
-
#initialize(opts = {}) ⇒ Element
constructor
Create an Element (inherited from Vidalia::Artifact).
-
#retrieve(inparams = {}) ⇒ Object
Call the “retrieve” function.
-
#set(inparams = {}) ⇒ Object
Call the “set” function.
-
#update(inparams = {}) ⇒ Object
Call the “update” function.
-
#verify(inparams = {}) ⇒ Object
Call the “verify” function.
Methods inherited from Artifact
#add_child, #get_child, #number_of_children, #set_parent
Constructor Details
#initialize(opts = {}) ⇒ Element
Create an Element (inherited from Vidalia::Artifact)
Initializes a Vidalia::Element using the data set in Vidalia::Element.define. If such data does not exist, this routine will error out. This ensures that all Elements have been predefined.
Options
Takes a hash as input where the current options are:
name
-
specifies the name of the Interface
parent
-
specifies the Vidalia::Identifier of the parent object
Example
$$$ Example needed $$$
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/vidalia/element.rb', line 45 def initialize(opts = {}) o = { :name => nil, :parent => nil, :definition => nil, }.merge(opts) @type = Vidalia::Element super if o[:definition] my_def = o[:definition] Vidalia::checkvar(my_def,Vidalia::Element,self.class.ancestors,"definition") @get_function = my_def.get_function @set_function = my_def.set_function @retrieve_function = my_def.retrieve_function @verify_function = my_def.verify_function @confirm_function = my_def.confirm_function @update_function = my_def.update_function if @get_function add_generic_retrieve() unless @retrieve_function add_generic_verify() unless @verify_function add_generic_confirm() unless @confirm_function if @set_function add_generic_update() unless @update_function end end end end |
Instance Attribute Details
#confirm_function ⇒ Object (readonly)
Returns the value of attribute confirm_function.
5 6 7 |
# File 'lib/vidalia/element.rb', line 5 def confirm_function @confirm_function end |
#get_function ⇒ Object (readonly)
Returns the value of attribute get_function.
5 6 7 |
# File 'lib/vidalia/element.rb', line 5 def get_function @get_function end |
#init_block ⇒ Object
Returns the value of attribute init_block.
21 22 23 |
# File 'lib/vidalia/dsl.rb', line 21 def init_block @init_block end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/vidalia/element.rb', line 5 def name @name end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
5 6 7 |
# File 'lib/vidalia/element.rb', line 5 def parent @parent end |
#retrieve_function ⇒ Object (readonly)
Returns the value of attribute retrieve_function.
5 6 7 |
# File 'lib/vidalia/element.rb', line 5 def retrieve_function @retrieve_function end |
#set_function ⇒ Object (readonly)
Returns the value of attribute set_function.
5 6 7 |
# File 'lib/vidalia/element.rb', line 5 def set_function @set_function end |
#update_function ⇒ Object (readonly)
Returns the value of attribute update_function.
5 6 7 |
# File 'lib/vidalia/element.rb', line 5 def update_function @update_function end |
#verify_function ⇒ Object (readonly)
Returns the value of attribute verify_function.
5 6 7 |
# File 'lib/vidalia/element.rb', line 5 def verify_function @verify_function end |
Class Method Details
.copy_from(source) ⇒ Object
Copy an Interface from another Interface (inherited from Vidalia::Artifact)
Options
Takes one parameter:
source
-
specifies the name of the Interface to copy from
Example
$$$ Example Needed $$$
172 173 174 |
# File 'lib/vidalia/element.rb', line 172 def self.copy_from(source) super end |
.define(opts = {}, &block) ⇒ Object
Define an Element
This routine takes a Vidalia::ObjectDefinition and adds an Element definition to the associated Object.
Options
Takes a hash as input where the current options are:
name
-
specifies the name of the Element
parent
-
specifies the Object that the Element is associated with
block
-
specifies the block of code to be run when the Element is initialized
Example
$$$ Example needed $$$
24 25 26 |
# File 'lib/vidalia/element.rb', line 24 def self.define(opts = {}, &block) Vidalia::ElementDefinition.new(opts,&block) end |
Instance Method Details
#add_confirm(&block) ⇒ Object
Add a “confirm” function
This function will be called to obtain the data element value from the Object. A call to “confirm” really makes the most sense AFTER obtaining data from the database/API.
Options
Takes a block to be executed when “confirm” for this Element is invoked. The input block should take a hash as a parameter.
Example
$$$ Example needed $$$
348 349 350 |
# File 'lib/vidalia/element.rb', line 348 def add_confirm(&block) @confirm_function = block end |
#add_generic_confirm ⇒ Object
Set the generic confirm directive for this Element
Options
Takes no parameters.
Example
$$$ Example Needed $$$
123 124 125 126 127 128 129 130 131 132 |
# File 'lib/vidalia/element.rb', line 123 def add_generic_confirm() add_confirm { |value| retval = false found_value = retrieve(value) if value == found_value retval = true end retval } end |
#add_generic_retrieve ⇒ Object
Set the generic retrieve directive for this Element
Options
Takes no parameters.
Example
$$$ Example Needed $$$
85 86 87 |
# File 'lib/vidalia/element.rb', line 85 def add_generic_retrieve() @retrieve_function = @get_function end |
#add_generic_update ⇒ Object
Set the generic update directive for this Element
Options
Takes no parameters.
Example
$$$ Example Needed $$$
145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/vidalia/element.rb', line 145 def add_generic_update() add_update { |value| new_value = value found_value = retrieve() if new_value == found_value capital_text = @name capital_text[0] = capital_text[0].capitalize Vidalia.log("#{capital_text} is already set to \"#{new_value}\"") else Vidalia.log("Entering #{@name}: \"#{new_value}\" (was \"#{found_value}\")") set(new_value) end } end |
#add_generic_verify ⇒ Object
Set the generic verify directive for this Element
Options
Takes no parameters.
Example
$$$ Example Needed $$$
100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/vidalia/element.rb', line 100 def add_generic_verify() add_verify { |value| found_value = retrieve(value) if value == found_value Vidalia.log("Verified #{@name} to be \"#{value}\"") else raise "Expected #{@name} to be \"#{value}\", but found \"#{found_value}\" instead" end true } end |
#add_get(&block) ⇒ Object
Add a “get” function
This function will be called to obtain the data element value from the Object. A call to “get” really makes the most sense AFTER obtaining data from the database/API.
Options
Takes a block to be executed when “get” for this Element is invoked. The input block should take a hash as a parameter.
Example
$$$ Example needed $$$
192 193 194 |
# File 'lib/vidalia/element.rb', line 192 def add_get(&block) @get_function = block end |
#add_retrieve(&block) ⇒ Object
Add a “retrieve” function
This function will be called to obtain the data element value from the Object. A call to “retrieve” really makes the most sense AFTER obtaining data from the database/API.
Options
Takes a block to be executed when “retrieve” for this Element is invoked. The input block should take a hash as a parameter.
Example
$$$ Example needed $$$
270 271 272 |
# File 'lib/vidalia/element.rb', line 270 def add_retrieve(&block) @retrieve_function = block end |
#add_set(&block) ⇒ Object
Add a “set” function
This function will be called to set the element’s value in the Object. Object. A call to “set” really makes the most sense BEFORE making an alteration to the Object data via database/API call.
Options
Takes a block to be executed when “set” for this Element is invoked. The input block should take a hash as a parameter.
Example
$$$ Example needed $$$
231 232 233 |
# File 'lib/vidalia/element.rb', line 231 def add_set(&block) @set_function = block end |
#add_update(&block) ⇒ Object
Add a “update” function
This function will be called to obtain the data element value from the Object. A call to “update” really makes the most sense AFTER obtaining data from the database/API.
Options
Takes a block to be executed when “update” for this Element is invoked. The input block should take a hash as a parameter.
Example
$$$ Example needed $$$
387 388 389 |
# File 'lib/vidalia/element.rb', line 387 def add_update(&block) @update_function = block end |
#add_verify(&block) ⇒ Object
Add a “verify” function
This function will be called to obtain the data element value from the Object. A call to “verify” really makes the most sense AFTER obtaining data from the database/API.
Options
Takes a block to be executed when “verify” for this Element is invoked. The input block should take a hash as a parameter.
Example
$$$ Example needed $$$
309 310 311 |
# File 'lib/vidalia/element.rb', line 309 def add_verify(&block) @verify_function = block end |
#confirm(inparams = {}) ⇒ Object
Call the “confirm” function
Call the pre-defined “confirm” function for this element.
Options
Takes a hash as input, with data as expected by the pre-defined “confirm” block.
Example
$$$ Example needed $$$
366 367 368 369 |
# File 'lib/vidalia/element.rb', line 366 def confirm(inparams = {}) block = @confirm_function instance_exec(inparams,&block) end |
#get(inparams = {}) ⇒ Object
Call the “get” function
Call the pre-defined “get” function for this element.
Options
Takes a hash as input, with data as expected by the pre-defined “get” block.
Example
$$$ Example needed $$$
210 211 212 213 |
# File 'lib/vidalia/element.rb', line 210 def get(inparams = {}) block = @get_function instance_exec(inparams,&block) end |
#retrieve(inparams = {}) ⇒ Object
Call the “retrieve” function
Call the pre-defined “retrieve” function for this element.
Options
Takes a hash as input, with data as expected by the pre-defined “retrieve” block.
Example
$$$ Example needed $$$
288 289 290 291 |
# File 'lib/vidalia/element.rb', line 288 def retrieve(inparams = {}) block = @retrieve_function instance_exec(inparams,&block) end |
#set(inparams = {}) ⇒ Object
Call the “set” function
Call the pre-defined “set” function for this element.
Options
Takes a hash as input, with data as expected by the pre-defined “set” block.
Example
$$$ Example needed $$$
249 250 251 252 |
# File 'lib/vidalia/element.rb', line 249 def set(inparams = {}) block = @set_function instance_exec(inparams,&block) end |
#update(inparams = {}) ⇒ Object
Call the “update” function
Call the pre-defined “update” function for this element.
Options
Takes a hash as input, with data as expected by the pre-defined “update” block.
Example
$$$ Example needed $$$
405 406 407 408 |
# File 'lib/vidalia/element.rb', line 405 def update(inparams = {}) block = @update_function instance_exec(inparams,&block) end |
#verify(inparams = {}) ⇒ Object
Call the “verify” function
Call the pre-defined “verify” function for this element.
Options
Takes a hash as input, with data as expected by the pre-defined “verify” block.
Example
$$$ Example needed $$$
327 328 329 330 |
# File 'lib/vidalia/element.rb', line 327 def verify(inparams = {}) block = @verify_function instance_exec(inparams,&block) end |