Sha256: f97e105cbc0b07b6ae6219bf6c7156e9c589d31bd8e06d1f1c93278b2787b038

Contents?: true

Size: 1.47 KB

Versions: 10

Compression:

Stored size: 1.47 KB

Contents

module Nanoc::Int
  # @api private
  class Site
    include Nanoc::Int::ContractsSupport

    attr_accessor :compiler

    contract C::KeywordArgs[config: Nanoc::Int::Configuration, code_snippets: C::IterOf[Nanoc::Int::CodeSnippet], items: C::IterOf[Nanoc::Int::Item], layouts: C::IterOf[Nanoc::Int::Layout]] => C::Any
    def initialize(config:, code_snippets:, items:, layouts:)
      @config = config
      @code_snippets = code_snippets
      @items = items
      @layouts = layouts

      ensure_identifier_uniqueness(@items, 'item')
      ensure_identifier_uniqueness(@layouts, 'layout')
    end

    contract C::None => self
    def compile
      compiler.run_all
      self
    end

    contract C::None => C::Named['Nanoc::Int::Compiler']
    def compiler
      @compiler ||= Nanoc::Int::CompilerLoader.new.load(self)
    end

    attr_reader :code_snippets
    attr_reader :config
    attr_reader :items
    attr_reader :layouts

    contract C::None => self
    def freeze
      config.freeze
      items.freeze
      layouts.freeze
      code_snippets.__nanoc_freeze_recursively
      self
    end

    contract C::IterOf[C::Or[Nanoc::Int::Item, Nanoc::Int::Layout]], String => self
    def ensure_identifier_uniqueness(objects, type)
      seen = Set.new
      objects.each do |obj|
        if seen.include?(obj.identifier)
          raise Nanoc::Int::Errors::DuplicateIdentifier.new(obj.identifier, type)
        end
        seen << obj.identifier
      end
      self
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
nanoc-4.6.1 lib/nanoc/base/entities/site.rb
nanoc-4.6.0 lib/nanoc/base/entities/site.rb
nanoc-4.5.4 lib/nanoc/base/entities/site.rb
nanoc-4.5.3 lib/nanoc/base/entities/site.rb
nanoc-4.5.2 lib/nanoc/base/entities/site.rb
nanoc-4.5.1 lib/nanoc/base/entities/site.rb
nanoc-4.5.0 lib/nanoc/base/entities/site.rb
nanoc-4.4.7 lib/nanoc/base/entities/site.rb
nanoc-4.4.6 lib/nanoc/base/entities/site.rb
nanoc-4.4.5 lib/nanoc/base/entities/site.rb