Sha256: 023ceac18148bd0ff632b8a395002ff6649673cf68f87cb263e377ad809618dc

Contents?: true

Size: 820 Bytes

Versions: 10

Compression:

Stored size: 820 Bytes

Contents

module Replyr
  module HandleReply

    def self.included(base)
      base.extend ClassMethods  
    end
  
    module ClassMethods 
    
      # Usage:
      # class Comment < ActiveRecord::Base
      #   handle_reply do |comment, user, text, files|
      #     Comment.create(body: text, author: user)
      #   end
      # end
      #
      def handle_reply(*options, &block)	
    		options = options.extract_options!

        define_method :handle_reply do |user, text, files = nil|
          block.call(self, user, text, files) 
        end
  
        define_method :reply_address_object_for_user do |user|
          ReplyAddress.new(self, user)
        end
        
        define_method :reply_address_for_user do |user|
          reply_address_object_for_user(user).to_s
        end

      end
    end

  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
replyr-0.1.0 lib/replyr/handle_reply.rb
replyr-0.0.9 lib/replyr/handle_reply.rb
replyr-0.0.8 lib/replyr/handle_reply.rb
replyr-0.0.7 lib/replyr/handle_reply.rb
replyr-0.0.6 lib/replyr/handle_reply.rb
replyr-0.0.5 lib/replyr/handle_reply.rb
replyr-0.0.4 lib/replyr/handle_reply.rb
replyr-0.0.3 lib/replyr/handle_reply.rb
replyr-0.0.2 lib/replyr/handle_reply.rb
replyr-0.0.1 lib/replyr/handle_reply.rb