Sha256: 9b8b7ab421fcba1fb082ec3112a7bdbd6c9f3d673f6e600ff239394b0c9b761e

Contents?: true

Size: 1.96 KB

Versions: 10

Compression:

Stored size: 1.96 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)
            Reality::Generators.error("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

10 entries across 10 versions & 1 rubygems

Version Path
reality-generators-1.14.0 lib/reality/generators/template_set.rb
reality-generators-1.13.0 lib/reality/generators/template_set.rb
reality-generators-1.12.0 lib/reality/generators/template_set.rb
reality-generators-1.11.0 lib/reality/generators/template_set.rb
reality-generators-1.10.0 lib/reality/generators/template_set.rb
reality-generators-1.9.0 lib/reality/generators/template_set.rb
reality-generators-1.8.0 lib/reality/generators/template_set.rb
reality-generators-1.7.0 lib/reality/generators/template_set.rb
reality-generators-1.6.0 lib/reality/generators/template_set.rb
reality-generators-1.5.0 lib/reality/generators/template_set.rb