Sha256: a3af113e15c5cc0e853757a6014615c3a45d44ad6beec9d9916f06ce1f9b8dd8

Contents?: true

Size: 1.56 KB

Versions: 11

Compression:

Stored size: 1.56 KB

Contents

# frozen_string_literal: true

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

    attr_reader :code_snippets
    attr_reader :config
    attr_accessor :data_source
    attr_accessor :compiler

    contract C::KeywordArgs[config: Nanoc::Int::Configuration, code_snippets: C::IterOf[Nanoc::Int::CodeSnippet], data_source: C::Maybe[C::Named['Nanoc::DataSource']]] => C::Any
    def initialize(config:, code_snippets:, data_source:)
      @config = config
      @code_snippets = code_snippets
      @data_source = data_source

      ensure_identifier_uniqueness(@data_source.items, 'item')
      ensure_identifier_uniqueness(@data_source.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

    def items
      @data_source.items
    end

    def layouts
      @data_source.layouts
    end

    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

11 entries across 11 versions & 1 rubygems

Version Path
nanoc-4.8.5 lib/nanoc/base/entities/site.rb
nanoc-4.8.4 lib/nanoc/base/entities/site.rb
nanoc-4.8.3 lib/nanoc/base/entities/site.rb
nanoc-4.8.2 lib/nanoc/base/entities/site.rb
nanoc-4.8.1 lib/nanoc/base/entities/site.rb
nanoc-4.8.0 lib/nanoc/base/entities/site.rb
nanoc-4.7.14 lib/nanoc/base/entities/site.rb
nanoc-4.7.13 lib/nanoc/base/entities/site.rb
nanoc-4.7.12 lib/nanoc/base/entities/site.rb
nanoc-4.7.11 lib/nanoc/base/entities/site.rb
nanoc-4.7.10 lib/nanoc/base/entities/site.rb