Sha256: 8d90da4ff9d92b810807160fa4ae6d86a3eff500826f8bc6fab39160826d771c

Contents?: true

Size: 1.1 KB

Versions: 1

Compression:

Stored size: 1.1 KB

Contents

module Ubiquitously
  module Account
    module Loggable
      def self.included(base)
        base.extend ClassMethods
        base.loggable
        base.send :include, InstanceMethods
      end
    
      module ClassMethods
        def loggable
          before_login do
            if authorized?
              @logged_in = true 
              return false
            end
            logger.info "[login:before] #{inspect}"
          end
          
          after_login do
            user.save
            logger.info "[login:after] #{inspect}"
          end
        end
        
        def service
          name.split("::")[1].underscore.gsub(/\s+/, "_")
        end
        
        def logger
          Ubiquitously.logger
        end
      end
      
      module InstanceMethods
        def logger
          self.class.logger
        end
        
        def service
          self.class.service
        end
        
        def inspect
          "#<#{self.class.inspect} @username=#{username.inspect} @password=#{password.gsub(/./, "*").inspect} @service=#{service.inspect}>"
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ubiquitously-0.1.0 lib/ubiquitously/models/service/account/loggable.rb