Sha256: 9b35f1f71d2a22026edb549428351ac37db42908834bebaf4b47ff56b724d3ef

Contents?: true

Size: 1.4 KB

Versions: 2

Compression:

Stored size: 1.4 KB

Contents

# Result contains the request and all the effects that a specific request caused all over the models
module OhMyLog
  module Log
    class Result
      attr_reader :effects
      attr_reader :request

      def initialize(request)
        @request = request
        @effects = calculate_effects
      end

      # call this to record the current action done by the user
      def record!
        if OhMyLog::Log.configuration.print_log
          p "REQUEST"
          p @request.to_s
          p "RESPONSE" unless @effects.empty?
          @effects.each {|effect| p effect.to_s}
        end

        print_into_log

        #we can record everything that happend (OPTIONALL)
        if OhMyLog::Log.configuration.record_history
          OhMyLog::Log.history << self
        end
        #We always save the last operation recorded
        OhMyLog::Log.last_recorded = self
        #save this string on file or upload it somewhere
      end

      private

      def print_into_log
        OhMyLog::Log.configuration.log_instance.info('REQUEST')
        OhMyLog::Log.configuration.log_instance.info(@request.to_s)
        OhMyLog::Log.configuration.log_instance.info('RESPONSE') unless @effects.empty?
        @effects.each {|effect| OhMyLog::Log.configuration.log_instance.info(effect.to_s)}
      end

      def calculate_effects
        return OhMyLog::Log::targets.map {|target| Effect.new(target)}
      end

    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
oh_my_log-1.0.2 lib/oh_my_log/result.rb
oh_my_log-1.0.1 lib/oh_my_log/result.rb