Class: Whisperer::BaseDsl

Inherits:
Object
  • Object
show all
Defined in:
lib/whisperer/dsl/base.rb

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(container) ⇒ BaseDsl

Returns a new instance of BaseDsl.



43
44
45
# File 'lib/whisperer/dsl/base.rb', line 43

def initialize(container)
  @container = container
end

Class Attribute Details

.container_classObject (readonly)

Returns the value of attribute container_class.



4
5
6
# File 'lib/whisperer/dsl/base.rb', line 4

def container_class
  @container_class
end

Instance Attribute Details

#containerObject (readonly)

Returns the value of attribute container.



41
42
43
# File 'lib/whisperer/dsl/base.rb', line 41

def container
  @container
end

Class Method Details

.add_writer(name) ⇒ Object



34
35
36
37
38
# File 'lib/whisperer/dsl/base.rb', line 34

def add_writer(name)
  define_method(name) do |val|
    @container.public_send("#{name}=", val)
  end
end

.buildObject



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/whisperer/dsl/base.rb', line 22

def build
  if self.container_class
    new(
      self.container_class.new
    )
  else
    raise ArgumentError.new(
      'You should associate a container (model) with this dsl class, before building it'
    )
  end
end


18
19
20
# File 'lib/whisperer/dsl/base.rb', line 18

def link_container_class(val)
  @container_class = val
end


6
7
8
9
10
11
12
13
14
15
16
# File 'lib/whisperer/dsl/base.rb', line 6

def link_dsl(name)
  define_method(name) do |&block|
    class_name = Whisperer::Dsl.const_get(name.capitalize)

    sub_dsl = class_name.new(
      @container.public_send(name)
    )

    sub_dsl.instance_eval &block
  end
end