Module: Rostra::ActsAsRostra::ClassMethods

Defined in:
lib/rostra.rb

Instance Method Summary collapse

Instance Method Details

#rostra(&block) ⇒ Object

Include this method in your rostra‘d model to add the necessary accociations and and methods:

class User < ActiveRecord::Base
  rostra
end


20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/rostra.rb', line 20

def rostra(&block)
  has_many :questions, class_name: 'Rostra::Question'
  has_many :answers, class_name: 'Rostra::Answer'
  has_many :comments
  has_many :question_followings, class_name: 'Rostra::QuestionFollowing', :dependent => :destroy
  has_many :followed_questions, through: :question_followings, class_name: 'Rostra::Question', source: :question

  acts_as_voter

  include InstanceMethods

  if block_given?
    def Rostra.questions(&questions_block)
      Rostra::Question.class_eval(&questions_block)
    end

    def Rostra.answers(&answers_block)
      Rostra::Answer.class_eval(&answers_block)
    end

    Rostra.class_eval(&block)
  end

end