Sha256: c943aa3bf2bd06389b674b1b5f7ddbe096fb631a1e0a02d9b53185e72295aeeb

Contents?: true

Size: 1.08 KB

Versions: 1

Compression:

Stored size: 1.08 KB

Contents

module RedMatter
  # Loader - processes Redfile / config block
  # @!attr [rw] verbose
  #   @return [Bool]
  class Loader
    attr_accessor :verbose

    def initialize
      @assets = {}
      @verbose = false
      @total = 0.0
    end

    # Loads given code from string (`dat` parameter) or yielded block
    # @param dat [String]
    # @param block [Proc]
    # @return [RedMatter::Loader] self
    def load(dat, &block)
      if block
        instance_exec(&block)
      else
        instance_eval(dat, nil, 'Redfile')
      end
      @assets.each_pair do |name, asset|
        t1 = Time.now.to_f
        asset.process
        t2 = Time.now.to_f
        took = t2 - t1
        @total += took
        puts "`#{name}`: #{took.truncate(6)} seconds" if @verbose
      end
      puts "Total: #{@total.truncate(6)} seconds" if @verbose
      self
    end

    # Adds asset node
    # @param name [String]
    # @param block [Proc]
    # @return [RedMatter::Loader] self
    def asset(name, &block)
      @assets[name] = RedMatter::Asset.new(&block)
      @assets[name].name = name
      self
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
red_matter-0.1.0 lib/red_matter/loader.rb