Sha256: e15bced03148543cd7729deaa5935c663fa86101ec8641a02d1045c318cb2ba7

Contents?: true

Size: 1.44 KB

Versions: 2

Compression:

Stored size: 1.44 KB

Contents

module Appfuel
  module Domain

    # The Criteria represents the interface between the repositories and actions
    # or commands. The allow you to find entities in the application storage (
    # a database) without knowledge of that storage system. The criteria will
    # always refer to its queries in the domain language for which the repo is
    # responsible for mapping that query to its persistence layer.
    #
    # global.user
    # memberships.user
    #
    # exist: 'foo.bar exists id = 6'
    #
    # exits:
    #   domain: 'foo.bar'
    #   expr: 'id = 6'
    #
    #   settings:
    #     error_on_empty
    #     parser
    #     transform
    #
    #
    class ExistsCriteria < BaseCriteria
      #
      # @param domain [String] fully qualified domain name
      # @param opts   [Hash] options for initializing criteria
      # @return [Criteria]
      def initialize(domain_name, data = {})
        super
        expr(data[:expr]) if data[:expr]
      end

      def filter(str)
        domain_expr = parse_expr(str)
        if filters?
          fail "A filter expression has already been assigned"
        end

        if domain_expr.conjunction?
          fail "Only simple domain expressions are allowed for exists criteria"
        end

        if domain_expr.qualified?
          fail "Only allows relative domain attributes"
        end

        @filters = qualify_expr(domain_expr)
        self
      end

      private

    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
appfuel-0.2.5 lib/appfuel/domain/exists_criteria.rb
appfuel-0.2.4 lib/appfuel/domain/exists_criteria.rb