Sha256: 6409afdbef89ec53b9103d23d3f7447926e3be941e6c367198439d7e18c5fdf2

Contents?: true

Size: 1.94 KB

Versions: 4

Compression:

Stored size: 1.94 KB

Contents

#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

module Reality #nodoc
  module Generators #nodoc

    # A collection of templates
    class TemplateSet < Reality::BaseElement
      attr_reader :name
      attr_reader :container
      attr_accessor :required_template_sets
      attr_accessor :description

      def initialize(container, name, options = {}, &block)
        @container = container
        @name = name
        @required_template_sets = []
        super(options, &block)
        self.required_template_sets.each do |template_set_name|
          unless container.template_set_by_name?(template_set_name)
            raise "TemplateSet '#{self.name}' defined requirement on template set '#{template_set_name}' that does not exist."
          end
        end
        container.send(:register_template_set, self)
      end

      def templates
        template_map.values
      end

      def template_by_name?(name)
        !!template_map[name.to_s]
      end

      def template_by_name(name)
        template = template_map[name.to_s]
        Generators.error("Unable to locate template #{name}") unless template
        template
      end

      private

      def register_template(template)
        Generators.error("Template already exists with specified name #{template.name}") if template_map[template.name]
        template_map[template.name] = template
      end

      def template_map
        @templates ||= Reality::OrderedHash.new
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
reality-generators-1.3.0 lib/reality/generators/template_set.rb
reality-generators-1.2.0 lib/reality/generators/template_set.rb
reality-generators-1.1.0 lib/reality/generators/template_set.rb
reality-generators-1.0.0 lib/reality/generators/template_set.rb