Sha256: c059a08ce8f5c79b387b63a2e939ed9b668547272fd1e108efd6eeb657c49c80

Contents?: true

Size: 1.21 KB

Versions: 17

Compression:

Stored size: 1.21 KB

Contents

module IntercomRails

  module Proxy

    class User < Proxy

      proxy_delegator :id, :identity => true
      proxy_delegator :email, :identity => true
      proxy_delegator :name
      proxy_delegator :created_at

      PREDEFINED_POTENTIAL_USER_OBJECTS = [
        Proc.new { current_user },
        Proc.new { @user }
      ]

      def self.potential_user_objects
        if config.current.present?
          [Proc.new { instance_eval &IntercomRails.config.user.current }]
        else
          PREDEFINED_POTENTIAL_USER_OBJECTS
        end
      end

      def self.current_in_context(search_object)
        potential_user_objects.each do |potential_object|
          begin
            user_proxy = new(search_object.instance_eval(&potential_object), search_object)
            return user_proxy if user_proxy.valid?
          rescue NameError
            next
          end
        end

        raise NoUserFoundError
      end

      def standard_data
        super.tap do |hsh|
          hsh[:user_id] = hsh.delete(:id) if hsh.has_key?(:id)
        end
      end

      def valid?
        return false if user.blank? || user.respond_to?(:new_record?) && user.new_record?
        identity_present?
      end

    end

  end

end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
intercom-rails-0.2.25 lib/intercom-rails/proxy/user.rb
intercom-rails-0.2.24 lib/intercom-rails/proxy/user.rb
intercom-rails-0.2.23 lib/intercom-rails/proxy/user.rb
intercom-rails-0.2.22 lib/intercom-rails/proxy/user.rb
intercom-rails-0.2.21 lib/intercom-rails/proxy/user.rb
intercom-rails-0.2.20 lib/intercom-rails/proxy/user.rb
intercom-rails-0.2.19 lib/intercom-rails/proxy/user.rb
intercom-rails-0.2.18 lib/intercom-rails/proxy/user.rb
intercom-rails-0.2.17 lib/intercom-rails/proxy/user.rb
intercom-rails-0.2.16 lib/intercom-rails/proxy/user.rb
intercom-rails-0.2.15 lib/intercom-rails/proxy/user.rb
intercom-rails-0.2.14 lib/intercom-rails/proxy/user.rb
intercom-rails-0.2.13 lib/intercom-rails/proxy/user.rb
intercom-rails-0.2.12 lib/intercom-rails/proxy/user.rb
intercom-rails-0.2.11 lib/intercom-rails/proxy/user.rb
intercom-rails-0.2.10 lib/intercom-rails/proxy/user.rb
intercom-rails-0.2.9 lib/intercom-rails/proxy/user.rb