Sha256: d86c719ad9b39f87ebd2cb4bddfbb2badc57d5ebb935241475a9d43e85153c6f

Contents?: true

Size: 749 Bytes

Versions: 6

Compression:

Stored size: 749 Bytes

Contents

#
#       ActiveFacts Runtime API
#       RoleValues, manages the set of instances involved in a many_to_one relationship.
#
# Copyright (c) 2009 Clifford Heath. Read the LICENSE file.
#
require 'forwardable'

module ActiveFacts
  module API

    class RoleValues  #:nodoc:
      include Enumerable
      extend Forwardable

      def_delegators :@a, :each, :size, :empty?, :-

      def initialize
        @a = []
      end

      def +(a)
        @a.+(a.is_a?(RoleValues) ? [a] : a)
      end

      def single
        size > 1 ? nil : @a[0]
      end

      def update(old, value)
        @a.delete(old) if old
        @a << value if value
      end

      def verbalise
        "[#{@a.map(&:verbalise).join(", ")}]"
      end
    end

  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
activefacts-api-0.9.6 lib/activefacts/api/role_values.rb
activefacts-api-0.9.5 lib/activefacts/api/role_values.rb
activefacts-api-0.9.4 lib/activefacts/api/role_values.rb
activefacts-api-0.9.3 lib/activefacts/api/role_values.rb
activefacts-api-0.9.2 lib/activefacts/api/role_values.rb
activefacts-api-0.9.1 lib/activefacts/api/role_values.rb