Class: Vedeu::DSL::Menu

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

Overview

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Vedeu::DSL

#method_missing

Constructor Details

#initialize(model, client = nil) ⇒ Vedeu::DSL::Menu

Return a new instance of DSL::Menu.

Parameters:

  • model (Vedeu::Menu)
  • client (Object) (defaults to: nil)


19
20
21
22
# File 'lib/vedeu/dsl/components/menu.rb', line 19

def initialize(model, client = nil)
  @model  = model
  @client = client
end

Dynamic Method Handling

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

Instance Attribute Details

#clientObject (readonly, private)

Returns:

  • (Object)


79
80
81
# File 'lib/vedeu/dsl/components/menu.rb', line 79

def client
  @client
end

#modelMenu (readonly, private)

Returns:



82
83
84
# File 'lib/vedeu/dsl/components/menu.rb', line 82

def model
  @model
end

Instance Method Details

#item(element) ⇒ Array

Add an individual item to the menu.

Examples:

menu 'my_menu' do
  item SomeClass.new
  item SomeClass.new

Parameters:

  • element (Object)

    An object you wish to add to the collection.

Returns:

  • (Array)


34
35
36
# File 'lib/vedeu/dsl/components/menu.rb', line 34

def item(element)
  model.collection << element
end

#items(collection = []) ⇒ Array

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.

Examples:

menu 'my_menu' do
  items [:item_1, :item_2, :item_3]
end

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)


57
58
59
# File 'lib/vedeu/dsl/components/menu.rb', line 57

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

#name(value) ⇒ String

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

Examples:

menu do
  name 'my_menu'
  ...

Parameters:

  • value (String)

Returns:

  • (String)


72
73
74
# File 'lib/vedeu/dsl/components/menu.rb', line 72

def name(value)
  model.name = value
end