Sha256: 60f376d18287e0be5cdf793c060220d3618e7a973a0a4775cb4fdd54b3e4b596

Contents?: true

Size: 839 Bytes

Versions: 35

Compression:

Stored size: 839 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::RuleDSL::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

35 entries across 35 versions & 1 rubygems

Version Path
nanoc-4.13.3 lib/nanoc/rule_dsl/rules_loader.rb
nanoc-4.13.2 lib/nanoc/rule_dsl/rules_loader.rb
nanoc-4.13.1 lib/nanoc/rule_dsl/rules_loader.rb
nanoc-4.13.0 lib/nanoc/rule_dsl/rules_loader.rb
nanoc-4.12.21 lib/nanoc/rule_dsl/rules_loader.rb
nanoc-4.12.20 lib/nanoc/rule_dsl/rules_loader.rb
nanoc-4.12.19 lib/nanoc/rule_dsl/rules_loader.rb
nanoc-4.12.18 lib/nanoc/rule_dsl/rules_loader.rb
nanoc-4.12.17 lib/nanoc/rule_dsl/rules_loader.rb
nanoc-4.12.16 lib/nanoc/rule_dsl/rules_loader.rb
nanoc-4.12.15 lib/nanoc/rule_dsl/rules_loader.rb
nanoc-4.12.14 lib/nanoc/rule_dsl/rules_loader.rb
nanoc-4.12.13 lib/nanoc/rule_dsl/rules_loader.rb
nanoc-4.12.12 lib/nanoc/rule_dsl/rules_loader.rb
nanoc-4.12.11 lib/nanoc/rule_dsl/rules_loader.rb
nanoc-4.12.10 lib/nanoc/rule_dsl/rules_loader.rb
nanoc-4.12.9 lib/nanoc/rule_dsl/rules_loader.rb
nanoc-4.12.8 lib/nanoc/rule_dsl/rules_loader.rb
nanoc-4.12.7 lib/nanoc/rule_dsl/rules_loader.rb
nanoc-4.12.6 lib/nanoc/rule_dsl/rules_loader.rb