Class: Tataru::TopDsl

Inherits:
Object
  • Object
show all
Defined in:
lib/tataru/top_dsl.rb

Overview

human representation of resources

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pool) ⇒ TopDsl

Returns a new instance of TopDsl.



8
9
10
11
# File 'lib/tataru/top_dsl.rb', line 8

def initialize(pool)
  @resources = {}
  @pool = pool
end

Instance Attribute Details

#resourcesObject (readonly)

Returns the value of attribute resources.



6
7
8
# File 'lib/tataru/top_dsl.rb', line 6

def resources
  @resources
end

Instance Method Details

#dep_graphObject



25
26
27
28
29
30
31
32
33
# File 'lib/tataru/top_dsl.rb', line 25

def dep_graph
  @resources.map do |name, resource_representation|
    deps = Set.new
    resource_representation.properties.each do |_key, value|
      deps += value.dependencies
    end
    [name, deps.to_a]
  end.to_h
end

#resource(symbol, name, &block) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/tataru/top_dsl.rb', line 13

def resource(symbol, name, &block)
  unless @pool.resource_desc_exist?(symbol)
    raise "no such resource: #{symbol}"
  end
  raise "already defined: #{name}" if @resources.key? name

  resource = ResourceDsl.new(name, @pool.resource_desc_for(symbol).new)
  resource.instance_eval(&block) if block

  @resources[name] = resource.representation
end