Class: ActsInRelation::Roles::Target

Inherits:
Base
  • Object
show all
Defined in:
lib/acts_in_relation/roles/target.rb

Constant Summary

Constants included from Supports::Verb

Supports::Verb::PATCHES

Instance Method Summary collapse

Methods inherited from Base

#actions, #initialize, #source, #target

Methods included from Supports::Verb

#pastize, #peoplize, #progressize

Constructor Details

This class inherits a constructor from ActsInRelation::Roles::Base

Instance Method Details

#defineObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/acts_in_relation/roles/target.rb', line 4

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?(#{source}_id: source.id)
      end
    RUBY
  end
end