Sha256: 5ee67de0bf2c1b72cc533c24b0127aceb106b3ddcc8a9177d5618fcf4a859235

Contents?: true

Size: 798 Bytes

Versions: 3

Compression:

Stored size: 798 Bytes

Contents

module CanTango::Api
  module Can
    module Dsl
      autoload_modules :Relation, :Scope
      
      def self.included(base)
        ::CanTango.config.user.relations.each do |relationship|
          base.class_eval %{
            def #{relationship}_of *models, &block
              options = models.extract_options!
              scope = options[:scope] || :user_account
              relation = Relation.new :#{relationship}, self, scope, *models, &block
              yield relation if block
              relation
            end
          }
        end
      end

      # creates a scope that enforces either using the user or user_account for determining relationship matches on the models
      def scope name, &block
        yield Scope.new name, self, &block
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
cantango-api-0.1.2 lib/cantango/api/can/dsl.rb
cantango-api-0.1.1 lib/cantango/api/can/dsl.rb
cantango-api-0.1.0 lib/cantango/api/can/dsl.rb