Sha256: 0da8587acc01c4ca5803981c76e7bba14f3ec3f6a382047888fe2c9e151524a7

Contents?: true

Size: 749 Bytes

Versions: 5

Compression:

Stored size: 749 Bytes

Contents

class ActionController::Base
  include Consul::Controller
  current_power do
    CanPlay::Power.new(current_user)
  end

  # 对current_power采用动态方法调用的装饰者。
  class PlayResourceObject < BasicObject
    def initialize(obj, klass)
      @obj = obj
      @klass = klass
    end

    def method_missing(method, *args, &block)
      if @obj.respond_to? "#{method}_evaluate_in_#{@klass.override_code}_scope"
        @obj.send("#{method}_evaluate_in_#{@klass.override_code}_scope", *args, &block)
      elsif @obj.respond_to? method
        @obj.send(method, *args, &block)
      else
        super
      end
    end
  end

  def play_resources
    @play_resource_object ||= PlayResourceObject.new(current_power, CanPlay)
  end

end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
can_play-0.2.9 lib/can_play/controller.rb
can_play-0.2.8 lib/can_play/controller.rb
can_play-0.2.7 lib/can_play/controller.rb
can_play-0.2.6 lib/can_play/controller.rb
can_play-0.2.5 lib/can_play/controller.rb