Class: Vedeu::DSL::Composition

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

Overview

DSL for creating collections of interfaces.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Vedeu::DSL

#method_missing

Constructor Details

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

Returns an instance of DSL::Composition.

Parameters:

  • model (Composition)
  • client (Object) (defaults to: nil)


15
16
17
18
# File 'lib/vedeu/dsl/composition.rb', line 15

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, protected)

Returns:

  • (Object)


78
79
80
# File 'lib/vedeu/dsl/composition.rb', line 78

def client
  @client
end

#modelComposition (readonly, protected)

Returns:



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

def model
  @model
end

Instance Method Details

#attributesHash (private)

Returns:

  • (Hash)


108
109
110
111
112
113
# File 'lib/vedeu/dsl/composition.rb', line 108

def attributes
  {
    client: client,
    parent: model,
  }
end

#existing_attributes(name) ⇒ Hash (private)

Retrieve the attributes of the interface by name.

Parameters:

  • name (String)

    The name of the interface.

Returns:

  • (Hash)


103
104
105
# File 'lib/vedeu/dsl/composition.rb', line 103

def existing_attributes(name)
  Vedeu.interfaces.by_name(name).attributes
end

#new_attributes(name) ⇒ Hash (private)

Parameters:

  • name (String)

    The name of the interface.

Returns:

  • (Hash)


95
96
97
# File 'lib/vedeu/dsl/composition.rb', line 95

def new_attributes(name)
  attributes.merge!(existing_attributes(name))
end

#template_attributes(name, lines) ⇒ Hash (private)

Parameters:

Returns:

  • (Hash)


89
90
91
# File 'lib/vedeu/dsl/composition.rb', line 89

def template_attributes(name, lines)
  new_attributes(name).merge!(lines: lines)
end

#template_for(name, filename, object = nil, options = {}) ⇒ Vedeu::Interfaces<Vedeu::Interface>

TODO:

More documentation required.

Load content from an ERb template.

Examples:

Vedeu.renders do
  template_for('my_interface',
               '/path/to/template.erb',
               @some_object, options)

Parameters:

  • name (String)

    The name of interface for which this template’s content belongs to.

  • filename (String)

    The filename (including path) to the template to be used.

  • object (Object) (defaults to: nil)

    The object for which the values of template’s variables can be obtained.

  • options (Hash) (defaults to: {})

    See Wordwrap

Returns:



65
66
67
68
69
70
71
72
# File 'lib/vedeu/dsl/composition.rb', line 65

def template_for(name, filename, object = nil, options = {})
  content = Vedeu::Template.parse(object, filename)
  lines   = Vedeu::Wordwrap.for(content, options)

  new_model = model.member.build(template_attributes(name, lines))

  model.add(new_model)
end

#view(name = '', &block) ⇒ Vedeu::Interfaces<Vedeu::Interface>

TODO:

More documentation required.

Define a view.

A view is just an Interface object.

When a view already exists, we take its attributes and use them as the basis for the newly defined view. This way we don’t need to specify everything again.

Examples:

view 'my_interface' do
  ...

Parameters:

  • name (String) (defaults to: '')

    The name of the interface you are targetting for this view.

  • block (Proc)

    The directives you wish to send to this interface.

Returns:

Raises:

  • (InvalidSyntax)

    The required block was not given.



39
40
41
42
43
44
45
# File 'lib/vedeu/dsl/composition.rb', line 39

def view(name = '', &block)
  fail InvalidSyntax, 'block not given' unless block_given?

  new_model = model.member.build(new_attributes(name), &block)

  model.add(new_model)
end