Sha256: 7a82decaec6e8a49d0bc66e55f41f2f12185a781435589bec1c6d1ef3039a00f

Contents?: true

Size: 1.53 KB

Versions: 13

Compression:

Stored size: 1.53 KB

Contents

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

13 entries across 13 versions & 1 rubygems

Version Path
nanoc-4.7.9 lib/nanoc/base/entities/site.rb
nanoc-4.7.8 lib/nanoc/base/entities/site.rb
nanoc-4.7.7 lib/nanoc/base/entities/site.rb
nanoc-4.7.6 lib/nanoc/base/entities/site.rb
nanoc-4.7.5 lib/nanoc/base/entities/site.rb
nanoc-4.7.4 lib/nanoc/base/entities/site.rb
nanoc-4.7.3 lib/nanoc/base/entities/site.rb
nanoc-4.7.2 lib/nanoc/base/entities/site.rb
nanoc-4.7.1 lib/nanoc/base/entities/site.rb
nanoc-4.7.0 lib/nanoc/base/entities/site.rb
nanoc-4.6.4 lib/nanoc/base/entities/site.rb
nanoc-4.6.3 lib/nanoc/base/entities/site.rb
nanoc-4.6.2 lib/nanoc/base/entities/site.rb