Sha256: 99fd6135e467a630f7b13bacddad9e197fce1150e4c9148f6412157cace0c3df

Contents?: true

Size: 1 KB

Versions: 1

Compression:

Stored size: 1 KB

Contents

require 'triad'
require 'surrounded/context_errors'
module Surrounded
  module Context
    class InvalidRole < ::Triad::ItemNotPresent; end

    class RoleMap

      class << self
        def from_base(klass=::Triad)
          role_mapper = Class.new(::Surrounded::Context::RoleMap)
          num = __LINE__; role_mapper.class_eval %{
            def container
              @container ||= #{klass}.new
            end
          }, __FILE__, num
          %w{ update each values keys }.each do |meth|
            num = __LINE__; role_mapper.class_eval %{
              def #{meth}(*args, &block)
                container.send(:#{meth}, *args, &block)
              end
            }, __FILE__, num
          end
          role_mapper
        end
      end

      def role?(role)
        keys.include?(role)
      end

      def role_player?(object)
        !values(object).empty?
      rescue ::Triad::ItemNotPresent
        false
      end

      def assigned_player(role)
        values(role).first
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
surrounded-0.9.10 lib/surrounded/context/role_map.rb