Sha256: d16a87a56f37907891db63c4747635dcb6281576ef3cc1c8368d486f9c42cb72

Contents?: true

Size: 996 Bytes

Versions: 2

Compression:

Stored size: 996 Bytes

Contents

module ActiveRecord
  module BelongsToAuthor
    def self.included(base)
      base.extend ActMacro
    end

    module ActMacro
      def belongs_to_user(*args)
        options = args.extract_options!
        args = (args.empty? ? [:user] : args)
        belongs_to_cacheable *args.dup << options # FIXME should not be polymorphic!
        
        args.each do |name|
          class_eval <<-code, __FILE__, __LINE__
            def #{name}_ip
              #{name}.ip if #{name} && #{name}.respond_to?(:ip)
            end

            def #{name}_agent
              #{name}.agent if #{name} && #{name}.respond_to?(:agent)
            end

            def #{name}_referer
              #{name}.referer if #{name} && #{name}.respond_to?(:referer)
            end
          code
        end
      end

      def belongs_to_author(*args)
        options = args.extract_options!
        args = (args.empty? ? [:author] : args) << options
        belongs_to_user *args
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 2 rubygems

Version Path
adva_user-0.0.1 lib/active_record/belongs_to_author.rb
adva-0.0.1 adva_user/lib/active_record/belongs_to_author.rb