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)


18
19
20
21
# File 'lib/vedeu/dsl/composition.rb', line 18

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)


53
54
55
# File 'lib/vedeu/dsl/composition.rb', line 53

def client
  @client
end

#modelComposition (readonly, private)

Returns:



56
57
58
# File 'lib/vedeu/dsl/composition.rb', line 56

def model
  @model
end

Instance Method Details

#attributesHash (private)

Returns:

  • (Hash)


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

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

#existing_interface_attributes(name) ⇒ Hash (private)

Parameters:

  • name (String)

    The name of the interface.

Returns:

  • (Hash)


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

def existing_interface_attributes(name)
  if model.repository.registered?(name)
    stored = model.repository.find(name)
    stored.attributes

  else
    { name: name }

  end
end

#new_attributes(name) ⇒ Hash (private)

Parameters:

  • name (String)

    The name of the interface.

Returns:

  • (Hash)


60
61
62
# File 'lib/vedeu/dsl/composition.rb', line 60

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

#view(name = '', &block) ⇒ Vedeu::Model::Collection<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.



42
43
44
45
46
47
48
# File 'lib/vedeu/dsl/composition.rb', line 42

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