Class: Vedeu::Menus::DSL

Inherits:
Object
  • Object
show all
Includes:
DSL
Defined in:
lib/vedeu/menus/dsl.rb

Overview

Provides the mechanism to create menus within client applications and use events to drive them.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Vedeu::DSL

Instance Attribute Details

#clientObject (readonly, protected) Originally defined in module DSL

Returns The object instance where the DSL is being used.

Returns:

  • (Object)

    The object instance where the DSL is being used.

#modelvoid (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.

Parameters:

  • block (Proc)

Returns:

  • (Object)


51
52
53
# File 'lib/vedeu/menus/dsl.rb', line 51

def client(&block)
  eval('self', block.binding)
end

Register a menu by name which will display a collection of items for your users to select; and provide interactivity within your application.

Examples:

Vedeu.menu :my_interface do
  items [:item_1, :item_2, :item_3]
  # ...
end

Vedeu.menu do
  name :menus_must_have_a_name
  items Track.all_my_favourites
  # ...
end

Parameters:

  • name (String|Symbol) (defaults to: '')
  • block (Proc)

    A set of attributes which define the features of the menu. See #items and #name.

Returns:

  • (API::Menu)

Raises:



37
38
39
40
41
42
43
# File 'lib/vedeu/menus/dsl.rb', line 37

def menu(name = '', &block)
  fail Vedeu::Error::RequiresBlock unless block_given?

  attributes = { client: client(&block), name: name }

  Vedeu::Menus::Menu.build(attributes, &block).store
end

Instance Method Details

#attributesHash<Symbol => void> (private) Originally defined in module DSL

Note:

Specific DSL classes may be overriding this method.

Returns the default attributes for the new model.

Returns:

  • (Hash<Symbol => void>)

#initialize(model, client = nil) ⇒ void Originally defined in module DSL

Returns an instance of the DSL class including Vedeu::DSL.

Parameters:

  • model (void)

    The model class which the DSL class is wrapping.

  • client (void) (defaults to: nil)

    The class where the DSL methods are being used.

#item(element) ⇒ Array Also known as: item=

Add an individual item to the menu.

Parameters:

  • element (Object)

    An object you wish to add to the collection.

    Vedeu.menu :my_menu do

    item SomeClass.new
    item SomeClass.new
    

    end

Returns:

  • (Array)


68
69
70
# File 'lib/vedeu/menus/dsl.rb', line 68

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.menu :my_menu do
  items [:item_1, :item_2, :item_3]
end

Vedeu.menu :my_playlist do
  items Track.all_my_favourites
end

Parameters:

  • collection (Array<Object>) (defaults to: [])

    A collection of objects which make up the menu items.

Returns:

  • (Array)


90
91
92
# File 'lib/vedeu/menus/dsl.rb', line 90

def items(collection = [])
  model.collection = collection
end

#name(name) ⇒ String Also known as: name=

The name of the menu. Used to reference the menu throughout your application’s execution lifetime.

Vedeu.menu do
  name :my_menu
  # ...
end

Parameters:

  • name (String|Symbol)

Returns:

  • (String)


105
106
107
# File 'lib/vedeu/menus/dsl.rb', line 105

def name(name)
  model.name = name
end