Sha256: 2a62ff205c8e0727a97bea422a3c05527c1bdb22bc3cf5c4ea600a433e135aeb

Contents?: true

Size: 835 Bytes

Versions: 31

Compression:

Stored size: 835 Bytes

Contents

# frozen_string_literal: true

module Nanoc::RuleDSL
  class RulesLoader
    def initialize(config, rules_collection)
      @dsl = Nanoc::RuleDSL::CompilerDSL.new(rules_collection, config)
    end

    def load
      # Find rules file
      rules_filenames = ['Rules', 'rules', 'Rules.rb', 'rules.rb']
      rules_filename = rules_filenames.find { |f| File.file?(f) }
      raise Nanoc::Int::Errors::NoRulesFileFound.new if rules_filename.nil?

      parse(rules_filename)
    end

    def parse(rules_filename)
      rules_filename = File.absolute_path(rules_filename)

      # Get rule data
      data = File.read(rules_filename)

      old_rules_filename = @dsl.rules_filename
      @dsl.rules_filename = rules_filename
      @dsl.instance_eval(data, rules_filename)
      @dsl.rules_filename = old_rules_filename
    end
  end
end

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
nanoc-4.11.14 lib/nanoc/rule_dsl/rules_loader.rb
nanoc-4.11.13 lib/nanoc/rule_dsl/rules_loader.rb
nanoc-4.11.12 lib/nanoc/rule_dsl/rules_loader.rb
nanoc-4.11.11 lib/nanoc/rule_dsl/rules_loader.rb
nanoc-4.11.10 lib/nanoc/rule_dsl/rules_loader.rb
nanoc-4.11.9 lib/nanoc/rule_dsl/rules_loader.rb
nanoc-4.11.8 lib/nanoc/rule_dsl/rules_loader.rb
nanoc-4.11.7 lib/nanoc/rule_dsl/rules_loader.rb
nanoc-4.11.6 lib/nanoc/rule_dsl/rules_loader.rb
nanoc-4.11.5 lib/nanoc/rule_dsl/rules_loader.rb
nanoc-4.11.4 lib/nanoc/rule_dsl/rules_loader.rb
nanoc-4.11.3 lib/nanoc/rule_dsl/rules_loader.rb
nanoc-4.11.2 lib/nanoc/rule_dsl/rules_loader.rb
nanoc-4.11.1 lib/nanoc/rule_dsl/rules_loader.rb
nanoc-4.11.0 lib/nanoc/rule_dsl/rules_loader.rb
nanoc-4.10.4 lib/nanoc/rule_dsl/rules_loader.rb
nanoc-4.10.3 lib/nanoc/rule_dsl/rules_loader.rb
nanoc-4.10.2 lib/nanoc/rule_dsl/rules_loader.rb
nanoc-4.10.1 lib/nanoc/rule_dsl/rules_loader.rb
nanoc-4.10.0 lib/nanoc/rule_dsl/rules_loader.rb