Sha256: e5b04aa3e04350506346341075741e2c913c18febc9e694cd592b091cb7de5f2

Contents?: true

Size: 938 Bytes

Versions: 2

Compression:

Stored size: 938 Bytes

Contents

module DiviningRod
  class Definition
    include Murge

    attr_accessor :prc, :group, :opts, :parent
    attr_writer :children

    def initialize(opts={}, &blk)
      @prc = blk
      @opts = opts
    end

    def evaluate(request)
      result = nil
      child_result = nil
      if @prc.call(request)
        result = self
        unless self.children.empty?
          self.children.each do |child|
            child_result = child.evaluate(request)
            break if child_result
          end
        end
      end
      child_result || result
    end

    def tags
      opts[:tags] || []
    end
    
    def opts
      if parent
        @murged_opts ||= murge(parent.opts, @opts)
      else
        @opts
      end
    end
    
    def format
      opts[:format]
    end
    
    def children
      @children ||= []
      @children.each do |child|
        child.parent ||= self
      end
      @children
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
divining_rod-0.5.0 lib/divining_rod/definition.rb
divining_rod-0.4.0 lib/divining_rod/definition.rb