Sha256: b4b81ec0de1165a6d865af7384c575a93bb1f482dc6ce22361dda1c81bfbd112

Contents?: true

Size: 1.06 KB

Versions: 4

Compression:

Stored size: 1.06 KB

Contents

module ActsAsCommentableMore
  module Helpers
    module Post
      module AssociationsHelper

        private

        def define_role_based_inflection(role, association_comment_name, join_options)
          send("define_role_based_inflection_#{Rails.version.first}", role, association_comment_name,join_options)
        end

        def define_role_based_inflection_3(role, association_comment_name, join_options)
          has_many "#{association_comment_name.to_s}".to_sym,
                   has_many_options(role, join_options).merge(:conditions => { role: role.to_s })
        end

        def define_role_based_inflection_4(role, association_comment_name, join_options)
          has_many "#{association_comment_name.to_s}".to_sym,
                   -> { includes(join_options[:as].to_sym, :user).where(role: role.to_s) },
                   has_many_options(role, join_options)
        end

        def has_many_options(role, join_options)
          { before_add: Proc.new { |post, comment| comment.role = role.to_s } }.merge(join_options)
        end

      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
acts_as_commentable_more-1.2.5 lib/acts_as_commentable_more/helpers/post/associations_helper.rb
acts_as_commentable_more-1.2.4 lib/acts_as_commentable_more/helpers/post/associations_helper.rb
acts_as_commentable_more-1.2.3 lib/acts_as_commentable_more/helpers/post/associations_helper.rb
acts_as_commentable_more-1.2.2 lib/acts_as_commentable_more/helpers/post/associations_helper.rb