Sha256: ba6df0936418bfbb336864f7d8ce0b8c06b5c61854df57a6c14444a9e3113894

Contents?: true

Size: 663 Bytes

Versions: 1

Compression:

Stored size: 663 Bytes

Contents

module ActsInRelation
  module Roles
    class Target < Base
      def define
        actions.each do |action|
          @class.class_eval <<-RUBY
            has_many :"#{action.pluralize}_as_target",
              foreign_key: :"target_#{target}_id",
              class_name: action.capitalize,
              dependent: :destroy

            has_many :"#{peoplize(action)}",
              through: :"#{action.pluralize}_as_target",
              source: :"#{source}"

            def #{pastize(action)}_by?(source)
              source.#{action.pluralize}.exists?(target_#{target}_id: id)
            end
          RUBY
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
acts_in_relation-0.2.2 lib/acts_in_relation/roles/target.rb