Sha256: 12259c56199df14e80f2c64b7222c96b07f140bcc8c8cb8c7cb88d8f96c99f26

Contents?: true

Size: 977 Bytes

Versions: 2

Compression:

Stored size: 977 Bytes

Contents

module Ironfan
  class Dsl

    class Realm < Ironfan::Dsl::Compute
      collection :clusters,       Ironfan::Dsl::Cluster,   :resolver => :deep_resolve

      magic :cluster_suffixes,    Whatever

      def initialize(attrs={},&block)
        cluster_names({})
        realm_name attrs[:name] if attrs[:name]
        super
      end

      def cluster(label, attrs={},&blk)
        new_name = [realm_name, label].join('_').to_sym
        cluster = Ironfan::Dsl::Cluster.new(name: new_name, owner: self, cluster_names: cluster_names)
        cluster_names[label] = new_name
        cluster.receive!(attrs, &blk)
        super(new_name, cluster)
      end

      def cluster_name suffix
        clusters.fetch([realm_name, suffix.to_s].join('_').to_sym).name.to_sym
      end
      
      def cluster_suffix suffix
        clusters.
          fetch([realm_name, suffix.to_s].join('_').to_sym).name.to_s.
          gsub(/^#{realm_name}_/, '').to_sym
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ironfan-4.12.3 lib/ironfan/dsl/realm.rb
ironfan-4.12.2 lib/ironfan/dsl/realm.rb