Sha256: d4755f8365fffc7eb1be7d2e3ee62e9ba66dc46d77daa6b272885e4c6ce4ad86

Contents?: true

Size: 538 Bytes

Versions: 4

Compression:

Stored size: 538 Bytes

Contents

module Degica
  class Context < BasicObject
    def initialize(actor)
      @actor = actor
      @focus = actor.focus || NilActionable.new
    end

    def actions
      (@actor.actions + @focus.actions).uniq(&:name)
    end

    def method_missing(method, *args)
      if match = @focus.actions.find { |action| action.name == method }
        @focus.do(match.name, *args)
      elsif match = @actor.actions.find { |action| action.name == method }
        @actor.do(match.name, *args)
      else
        super
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
degica-1.0.3 lib/degica/context.rb
degica-1.0.2 lib/degica/context.rb
degica-1.0.1 lib/degica/context.rb
degica-1.0.0 lib/degica/context.rb