Class: Destruct::DSL

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

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ DSL



3
4
5
6
# File 'lib/destruct/dsl.rb', line 3

def initialize(&block)
  @paths = []
  instance_eval(&block) if block
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method) ⇒ Object (private)



24
25
26
# File 'lib/destruct/dsl.rb', line 24

def method_missing(method, *)
  self[method]
end

Instance Method Details

#[](path) ⇒ Object



8
9
10
11
12
# File 'lib/destruct/dsl.rb', line 8

def [](path)
  self.class.new.tap do |dsl|
    @paths << [path, dsl]
  end
end

#pathsObject



14
15
16
17
18
19
20
# File 'lib/destruct/dsl.rb', line 14

def paths
  @paths.each_with_object([]) do |(key, dsl), paths|
    nested = dsl.paths
    paths << [key] if nested.empty?
    nested.each { |path| paths << path.unshift(key) }
  end
end