Sha256: d2da543796dd7c6285e3837805c3b51cfe5b7b8a08d62322d58db1abea784889

Contents?: true

Size: 988 Bytes

Versions: 1

Compression:

Stored size: 988 Bytes

Contents

module Kindergarten
  # Keep track of a single purpose
  class Purpose
    attr_reader :name, :methods, :sandbox, :subscriptions

    def initialize(name, sandbox)
      @name          = name
      @sandbox       = sandbox
      @methods       = {}
      @subscriptions = []
    end

    def add_perimeter(perimeter, instance)
      if perimeter.exposed_methods.blank?
        raise Kindergarten::Perimeter::NoExposedMethods.new(perimeter)
      end

      perimeter.exposed_methods.each do |name|
        if @methods.has_key?(name)
          warn "WARNING: overriding already sandboxed method #{@name}.#{name}"
        end

        @methods[name] = instance
      end
    end

    def method_missing(name, *args, &block)
      super

    rescue NoMethodError => ex
      unless methods.has_key?(name)
        raise ex
      end

      perimeter = methods[name]
      perimeter.governed(name, sandbox.unguarded?) do
        perimeter.send(name, *args, &block)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
kindergarten-0.1.0 lib/kindergarten/purpose.rb