Sha256: 546fabf4fbd296d8563d0753cc5bcb03e97e8ca7888b1cd66291568c2363c5b3

Contents?: true

Size: 665 Bytes

Versions: 18

Compression:

Stored size: 665 Bytes

Contents

module Softwear
  module Auth
    module BelongsToUser
      extend ActiveSupport::Concern

      module ClassMethods
        def belongs_to_user_called(name, options = {})
          foreign_key = "#{name}_id"

          class_eval <<-RUBY, __FILE__, __LINE__ + 1
            def #{name}
              @#{name} ||= User.find(#{name}_id)
            end

            def #{name}=(new)
              self.#{foreign_key} = new.id
              @#{name} = new
            end
          RUBY
        end

        def belongs_to_user
          belongs_to_user_called(:user)
        end
      end

      included do
        extend ClassMethods
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
softwear-lib-1.6.2 lib/softwear/auth/belongs_to_user.rb
softwear-lib-1.6.1 lib/softwear/auth/belongs_to_user.rb
softwear-lib-1.6.0 lib/softwear/auth/belongs_to_user.rb
softwear-lib-1.5.18 lib/softwear/auth/belongs_to_user.rb
softwear-lib-1.5.17 lib/softwear/auth/belongs_to_user.rb
softwear-lib-1.5.16 lib/softwear/auth/belongs_to_user.rb
softwear-lib-1.5.15 lib/softwear/auth/belongs_to_user.rb
softwear-lib-1.5.14 lib/softwear/auth/belongs_to_user.rb
softwear-lib-1.5.13 lib/softwear/auth/belongs_to_user.rb
softwear-lib-1.5.9 lib/softwear/auth/belongs_to_user.rb
softwear-lib-1.5.8 lib/softwear/auth/belongs_to_user.rb
softwear-lib-1.5.6 lib/softwear/auth/belongs_to_user.rb
softwear-lib-1.5.5 lib/softwear/auth/belongs_to_user.rb
softwear-lib-1.5.4 lib/softwear/auth/belongs_to_user.rb
softwear-lib-1.5.3 lib/softwear/auth/belongs_to_user.rb
softwear-lib-1.5.2 lib/softwear/auth/belongs_to_user.rb
softwear-lib-1.5.1 lib/softwear/auth/belongs_to_user.rb
softwear-lib-1.5.0 lib/softwear/auth/belongs_to_user.rb