Class: Tataru::TopDsl
- Inherits:
-
Object
- Object
- Tataru::TopDsl
- Defined in:
- lib/tataru/top_dsl.rb
Overview
human representation of resources
Instance Attribute Summary collapse
-
#resources ⇒ Object
readonly
Returns the value of attribute resources.
Instance Method Summary collapse
- #dep_graph ⇒ Object
-
#initialize(pool) ⇒ TopDsl
constructor
A new instance of TopDsl.
- #resource(symbol, name, &block) ⇒ Object
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
#resources ⇒ Object (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_graph ⇒ Object
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 |