Sha256: b355ef90954d4db7cff34cdd537f2787294519e88b240fe023b722ea76a42e92

Contents?: true

Size: 602 Bytes

Versions: 3

Compression:

Stored size: 602 Bytes

Contents

module Trestle
  class Hook
    attr_reader :name, :options, :block

    def initialize(name, options={}, &block)
      @name, @options, @block = name, options, block
    end

    def ==(other)
      other.is_a?(self.class) && name == other.name && options == other.options && block == other.block
    end

    def visible?(context)
      if options[:if]
        context.instance_exec(&options[:if])
      elsif options[:unless]
        !context.instance_exec(&options[:unless])
      else
        true
      end
    end

    def evaluate(context)
      context.instance_exec(&block)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
trestle-0.8.12 lib/trestle/hook.rb
trestle-0.8.11 lib/trestle/hook.rb
trestle-0.8.10 lib/trestle/hook.rb