Class: Vedeu::Menus::DSL
Overview
Provides the mechanism to create menus within client applications and use events to drive them.
Instance Attribute Summary collapse
-
#client ⇒ Object
included
from DSL
readonly
protected
The object instance where the DSL is being used.
-
#model ⇒ void
included
from DSL
readonly
protected
The new model object which the DSL is constructing.
Class Method Summary collapse
-
.client(&block) ⇒ Object
private
Returns the client object which called the DSL method.
-
.menu(name, &block) ⇒ API::Menu
Register a menu by name which will display a collection of items for your users to select; and provide interactivity within your application.
Instance Method Summary collapse
-
#attributes ⇒ Hash<Symbol => void>
included
from DSL
private
Returns the default attributes for the new model.
-
#initialize(model, client = nil) ⇒ void
included
from DSL
Returns a new instance of the DSL class including DSL.
-
#item(element) ⇒ Array
(also: #item=)
Add an individual item to the menu.
-
#items(collection = []) ⇒ Array
(also: #items=)
Define the items for the menu.
-
#method_missing(method, *args, &block) ⇒ void
included
from DSL
private
Attempts to find the missing method on the client object.
-
#name ⇒ NilClass|String|Symbol
included
from DSL
Returns the model name if available.
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Vedeu::DSL
Instance Attribute Details
#client ⇒ Object (readonly, protected) Originally defined in module DSL
Returns The object instance where the DSL is being used.
#model ⇒ void (readonly, protected) Originally defined in module DSL
This method returns an undefined value.
Returns The new model object which the DSL is constructing.
Class Method Details
.client(&block) ⇒ Object (private)
Returns the client object which called the DSL method.
55 56 57 |
# File 'lib/vedeu/menus/dsl.rb', line 55 def client(&block) eval('self', block.binding) end |
.menu(name, &block) ⇒ API::Menu
Register a menu by name which will display a collection of items for your users to select; and provide interactivity within your application.
40 41 42 43 44 45 46 47 |
# File 'lib/vedeu/menus/dsl.rb', line 40 def (name, &block) fail Vedeu::Error::MissingRequired unless name fail Vedeu::Error::RequiresBlock unless block_given? attributes = { client: client(&block), name: name } Vedeu::Menus::Menu.build(attributes, &block).store end |
Instance Method Details
#attributes ⇒ Hash<Symbol => void> (private) Originally defined in module DSL
Specific DSL classes may be overriding this method.
Returns the default attributes for the new model.
#initialize(model, client = nil) ⇒ void Originally defined in module DSL
Returns a new instance of the DSL class including Vedeu::DSL.
#item(element) ⇒ Array Also known as: item=
Add an individual item to the menu.
72 73 74 |
# File 'lib/vedeu/menus/dsl.rb', line 72 def item(element) model.collection << element end |
#items(collection = []) ⇒ Array Also known as: items=
Define the items for the menu. Most powerful when used with one of your model classes.
In the :my_playlist example below, your ‘Track` model may return a collection of tracks to populate the menu.
Vedeu. :my_menu do
items [:item_1, :item_2, :item_3]
end
Vedeu. :my_playlist do
items Track.all_my_favourites
end
94 95 96 |
# File 'lib/vedeu/menus/dsl.rb', line 94 def items(collection = []) model.collection = collection end |
#name ⇒ NilClass|String|Symbol Originally defined in module DSL
Returns the model name if available.