Sha256: 51c93be4789b96381ce37571ca0a81e1b4595f0655c3fb12b02d7c9f2004599d

Contents?: true

Size: 685 Bytes

Versions: 9

Compression:

Stored size: 685 Bytes

Contents

module Trestle
  class Hook
    require_relative "hook/helpers"
    require_relative "hook/set"

    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, *args)
      context.instance_exec(*args, &block)
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
trestle-0.10.1 lib/trestle/hook.rb
trestle-0.10.0 lib/trestle/hook.rb
trestle-0.10.0.pre2 lib/trestle/hook.rb
trestle-0.10.0.pre lib/trestle/hook.rb
trestle-0.9.8 lib/trestle/hook.rb
trestle-0.9.7 lib/trestle/hook.rb
trestle-0.9.6 lib/trestle/hook.rb
trestle-0.9.5 lib/trestle/hook.rb
trestle-0.9.4 lib/trestle/hook.rb