Class: Vidalia::ElementDefinition

Inherits:
Object
  • Object
show all
Defined in:
lib/vidalia/dsl.rb,
lib/vidalia/element_definition.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Create an Element Definition

Under the covers, the ElementDefinition will create an associated Element definition. Any instantiated Element under the parent Object 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 Element

parent

(required) specifies the name of the parent Object

Takes a block to be executed at initialization time

Example

$$$ Example needed $$$


25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/vidalia/element_definition.rb', line 25

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

  Vidalia::checkvar(o[:name],String,self.class.ancestors,"name")
  Vidalia::checkvar(o[:parent],Vidalia::ObjectDefinition,self.class.ancestors,"parent")

  o[:parent] = o[:parent].object
  @element = Vidalia::Element.new(o,&block)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth_id, &block) ⇒ Object



61
62
63
# File 'lib/vidalia/dsl.rb', line 61

def method_missing(meth_id, &block)
  method("add_#{meth_id}".to_sym).call(&block)
end

Instance Attribute Details

#childrenObject (readonly)

Returns the value of attribute children.



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

def children
  @children
end

#elementObject (readonly)

Returns the value of attribute element.



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

def element
  @element
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#parentObject (readonly)

Returns the value of attribute parent.



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

def parent
  @parent
end

Instance Method Details

#add_confirm(&block) ⇒ Object

Add a “confirm” function for a Defined Element

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 defined Element is invoked.

Example

$$$ Example needed $$$


146
147
148
149
150
151
# File 'lib/vidalia/element_definition.rb', line 146

def add_confirm(&block)
  if block.arity > 1
    raise "Vidalia::ElementDefinition.add_confirm block must take a single parameter"
  end
  @element.add_confirm &block
end

#add_get(&block) ⇒ Object

Add a “get” function for a Defined Element

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 defined Element is invoked.

Example

$$$ Example needed $$$


54
55
56
57
58
59
# File 'lib/vidalia/element_definition.rb', line 54

def add_get(&block)
  if block.arity > 1
    raise "Vidalia::ElementDefinition.add_get block must take a single parameter"
  end
  @element.add_get &block
end

#add_retrieve(&block) ⇒ Object

Add a “retrieve” function for a Defined Element

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 defined Element is invoked.

Example

$$$ Example needed $$$


100
101
102
103
104
105
# File 'lib/vidalia/element_definition.rb', line 100

def add_retrieve(&block)
  if block.arity > 1
    raise "Vidalia::ElementDefinition.add_retrieve block must take a single parameter"
  end
  @element.add_retrieve &block
end

#add_set(&block) ⇒ Object

Add a “set” function for a Defined Element

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 defined Element is invoked.

Example

$$$ Example needed $$$


77
78
79
80
81
82
# File 'lib/vidalia/element_definition.rb', line 77

def add_set(&block)
  if block.arity > 1
    raise "Vidalia::ElementDefinition.add_set block must take a single parameter"
  end
  @element.add_set &block
end

#add_update(&block) ⇒ Object

Add a “update” function for a Defined Element

This function will be called to obtain the data element value from the Object. A call to “update” really makes the most sense when updating data AFTER obtaining data from the database/API.

Options

Takes a block to be executed when “update” for this defined Element is invoked.

Example

$$$ Example needed $$$


169
170
171
172
173
174
# File 'lib/vidalia/element_definition.rb', line 169

def add_update(&block)
  if block.arity > 1
    raise "Vidalia::ElementDefinition.add_update block must take a single parameter"
  end
  @element.add_update &block
end

#add_verify(&block) ⇒ Object

Add a “verify” function for a Defined Element

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 defined Element is invoked.

Example

$$$ Example needed $$$


123
124
125
126
127
128
# File 'lib/vidalia/element_definition.rb', line 123

def add_verify(&block)
  if block.arity > 1
    raise "Vidalia::ElementDefinition.add_verify block must take a single parameter"
  end
  @element.add_verify &block
end

#init(&block) ⇒ Object



57
58
59
# File 'lib/vidalia/dsl.rb', line 57

def init(&block)
  @element.init_block = block
end