model_log 2.0.0 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
 - data/.github/ISSUE_TEMPLATE/bug_report.md +38 -0
 - data/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
 - data/.gitignore +0 -2
 - data/.rspec +3 -0
 - data/Gemfile +1 -1
 - data/README.md +2 -2
 - data/Rakefile +3 -0
 - data/lib/model_log.rb +32 -13
 - data/lib/model_log/config.rb +1 -1
 - data/lib/model_log/context.rb +6 -8
 - data/lib/model_log/controller.rb +8 -8
 - data/lib/model_log/log/content.rb +3 -3
 - data/lib/model_log/log/initializer.rb +18 -8
 - data/lib/model_log/log/processor.rb +9 -14
 - data/lib/model_log/logger.rb +6 -0
 - data/lib/model_log/modeller.rb +3 -12
 - data/lib/model_log/store.rb +4 -4
 - data/lib/model_log/version.rb +14 -1
 - data/model_log.gemspec +1 -1
 - metadata +5 -2
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA256:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: a91de84ee8086e12de0c20d29185423e70bae67dce1817914bd61ff25ba49430
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 5f4673b8501238e256fa379ec279dc626372eef84d17c860054854401ea533e8
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 71b7b4458b7de39674a4e435cd202c8b6d5a24083bd2c6ae97e85e35c6d351cd9453db66758404bc2896141fb041b62dedfd5db23cccb23463c77bd02d09a444
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: c615dd14cd292bd9755110ffc13fbab8a11080617a490cef0232084581d3ce6488a4e935b4a20553d9faaa879fa4afe135d6f841b511b7146059c62bc2eef9b4
         
     | 
| 
         @@ -0,0 +1,38 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            ---
         
     | 
| 
      
 2 
     | 
    
         
            +
            name: Bug report
         
     | 
| 
      
 3 
     | 
    
         
            +
            about: Create a report to help us improve
         
     | 
| 
      
 4 
     | 
    
         
            +
            title: ''
         
     | 
| 
      
 5 
     | 
    
         
            +
            labels: ''
         
     | 
| 
      
 6 
     | 
    
         
            +
            assignees: ''
         
     | 
| 
      
 7 
     | 
    
         
            +
             
     | 
| 
      
 8 
     | 
    
         
            +
            ---
         
     | 
| 
      
 9 
     | 
    
         
            +
             
     | 
| 
      
 10 
     | 
    
         
            +
            **Describe the bug**
         
     | 
| 
      
 11 
     | 
    
         
            +
            A clear and concise description of what the bug is.
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
            **To Reproduce**
         
     | 
| 
      
 14 
     | 
    
         
            +
            Steps to reproduce the behavior:
         
     | 
| 
      
 15 
     | 
    
         
            +
            1. Go to '...'
         
     | 
| 
      
 16 
     | 
    
         
            +
            2. Click on '....'
         
     | 
| 
      
 17 
     | 
    
         
            +
            3. Scroll down to '....'
         
     | 
| 
      
 18 
     | 
    
         
            +
            4. See error
         
     | 
| 
      
 19 
     | 
    
         
            +
             
     | 
| 
      
 20 
     | 
    
         
            +
            **Expected behavior**
         
     | 
| 
      
 21 
     | 
    
         
            +
            A clear and concise description of what you expected to happen.
         
     | 
| 
      
 22 
     | 
    
         
            +
             
     | 
| 
      
 23 
     | 
    
         
            +
            **Screenshots**
         
     | 
| 
      
 24 
     | 
    
         
            +
            If applicable, add screenshots to help explain your problem.
         
     | 
| 
      
 25 
     | 
    
         
            +
             
     | 
| 
      
 26 
     | 
    
         
            +
            **Desktop (please complete the following information):**
         
     | 
| 
      
 27 
     | 
    
         
            +
             - OS: [e.g. iOS]
         
     | 
| 
      
 28 
     | 
    
         
            +
             - Browser [e.g. chrome, safari]
         
     | 
| 
      
 29 
     | 
    
         
            +
             - Version [e.g. 22]
         
     | 
| 
      
 30 
     | 
    
         
            +
             
     | 
| 
      
 31 
     | 
    
         
            +
            **Smartphone (please complete the following information):**
         
     | 
| 
      
 32 
     | 
    
         
            +
             - Device: [e.g. iPhone6]
         
     | 
| 
      
 33 
     | 
    
         
            +
             - OS: [e.g. iOS8.1]
         
     | 
| 
      
 34 
     | 
    
         
            +
             - Browser [e.g. stock browser, safari]
         
     | 
| 
      
 35 
     | 
    
         
            +
             - Version [e.g. 22]
         
     | 
| 
      
 36 
     | 
    
         
            +
             
     | 
| 
      
 37 
     | 
    
         
            +
            **Additional context**
         
     | 
| 
      
 38 
     | 
    
         
            +
            Add any other context about the problem here.
         
     | 
| 
         @@ -0,0 +1,20 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            ---
         
     | 
| 
      
 2 
     | 
    
         
            +
            name: Feature request
         
     | 
| 
      
 3 
     | 
    
         
            +
            about: Suggest an idea for this project
         
     | 
| 
      
 4 
     | 
    
         
            +
            title: ''
         
     | 
| 
      
 5 
     | 
    
         
            +
            labels: ''
         
     | 
| 
      
 6 
     | 
    
         
            +
            assignees: ''
         
     | 
| 
      
 7 
     | 
    
         
            +
             
     | 
| 
      
 8 
     | 
    
         
            +
            ---
         
     | 
| 
      
 9 
     | 
    
         
            +
             
     | 
| 
      
 10 
     | 
    
         
            +
            **Is your feature request related to a problem? Please describe.**
         
     | 
| 
      
 11 
     | 
    
         
            +
            A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
            **Describe the solution you'd like**
         
     | 
| 
      
 14 
     | 
    
         
            +
            A clear and concise description of what you want to happen.
         
     | 
| 
      
 15 
     | 
    
         
            +
             
     | 
| 
      
 16 
     | 
    
         
            +
            **Describe alternatives you've considered**
         
     | 
| 
      
 17 
     | 
    
         
            +
            A clear and concise description of any alternative solutions or features you've considered.
         
     | 
| 
      
 18 
     | 
    
         
            +
             
     | 
| 
      
 19 
     | 
    
         
            +
            **Additional context**
         
     | 
| 
      
 20 
     | 
    
         
            +
            Add any other context or screenshots about the feature request here.
         
     | 
    
        data/.gitignore
    CHANGED
    
    
    
        data/.rspec
    ADDED
    
    
    
        data/Gemfile
    CHANGED
    
    
    
        data/README.md
    CHANGED
    
    | 
         @@ -48,7 +48,7 @@ To use a method other than `current_user` and an identity field other than `id`, 
     | 
|
| 
       48 
48 
     | 
    
         
             
            ModelLog.configure do |config|
         
     | 
| 
       49 
49 
     | 
    
         
             
              config.current_user_method    = :current_manager     # default: :current_user
         
     | 
| 
       50 
50 
     | 
    
         
             
              config.identity_field         = :username            # default: :id
         
     | 
| 
       51 
     | 
    
         
            -
              config.separator              =  
     | 
| 
      
 51 
     | 
    
         
            +
              config.separator              = "\t"                 # default: ' '
         
     | 
| 
       52 
52 
     | 
    
         
             
              config.logger_datetime_format = '%Y-%m-%d %H:%M:%S'
         
     | 
| 
       53 
53 
     | 
    
         
             
            end
         
     | 
| 
       54 
54 
     | 
    
         
             
            ```
         
     | 
| 
         @@ -111,4 +111,4 @@ end 
     | 
|
| 
       111 
111 
     | 
    
         | 
| 
       112 
112 
     | 
    
         
             
            ## Copyright
         
     | 
| 
       113 
113 
     | 
    
         | 
| 
       114 
     | 
    
         
            -
            Copyright (c) 2018- jk-sun. See LICENSE. 
     | 
| 
      
 114 
     | 
    
         
            +
            Copyright (c) 2018- jk-sun. See LICENSE.txt for further details.
         
     | 
    
        data/Rakefile
    CHANGED
    
    
    
        data/lib/model_log.rb
    CHANGED
    
    | 
         @@ -1,17 +1,30 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            require  
     | 
| 
       2 
     | 
    
         
            -
            require  
     | 
| 
       3 
     | 
    
         
            -
             
     | 
| 
       4 
     | 
    
         
            -
            require  
     | 
| 
       5 
     | 
    
         
            -
            require "model_log/modeller"
         
     | 
| 
       6 
     | 
    
         
            -
            require "model_log/logger"
         
     | 
| 
       7 
     | 
    
         
            -
            require "model_log/context"
         
     | 
| 
       8 
     | 
    
         
            -
            require "model_log/log/initializer"
         
     | 
| 
       9 
     | 
    
         
            -
            require "model_log/log/content"
         
     | 
| 
       10 
     | 
    
         
            -
            require "model_log/log/processor"
         
     | 
| 
       11 
     | 
    
         
            -
            require "model_log/helpers/context"
         
     | 
| 
       12 
     | 
    
         
            -
            require "model_log/default/formatter"
         
     | 
| 
      
 1 
     | 
    
         
            +
            require 'active_support'
         
     | 
| 
      
 2 
     | 
    
         
            +
            require 'active_support/core_ext/object/blank'
         
     | 
| 
      
 3 
     | 
    
         
            +
             
     | 
| 
      
 4 
     | 
    
         
            +
            require 'model_log/version'
         
     | 
| 
       13 
5 
     | 
    
         | 
| 
       14 
6 
     | 
    
         
             
            module ModelLog
         
     | 
| 
      
 7 
     | 
    
         
            +
              extend ActiveSupport::Autoload
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
      
 9 
     | 
    
         
            +
              autoload :Config,  'model_log/config'
         
     | 
| 
      
 10 
     | 
    
         
            +
              autoload :Store,   'model_log/store'
         
     | 
| 
      
 11 
     | 
    
         
            +
              autoload :Logger,  'model_log/logger'
         
     | 
| 
      
 12 
     | 
    
         
            +
              autoload :Context, 'model_log/context'
         
     | 
| 
      
 13 
     | 
    
         
            +
             
     | 
| 
      
 14 
     | 
    
         
            +
              module Log
         
     | 
| 
      
 15 
     | 
    
         
            +
                autoload :Initializer, 'model_log/log/initializer'
         
     | 
| 
      
 16 
     | 
    
         
            +
                autoload :Content,     'model_log/log/content'
         
     | 
| 
      
 17 
     | 
    
         
            +
                autoload :Processor,   'model_log/log/processor'
         
     | 
| 
      
 18 
     | 
    
         
            +
              end
         
     | 
| 
      
 19 
     | 
    
         
            +
             
     | 
| 
      
 20 
     | 
    
         
            +
              module Default
         
     | 
| 
      
 21 
     | 
    
         
            +
                autoload :Formatter, 'model_log/default/formatter'
         
     | 
| 
      
 22 
     | 
    
         
            +
              end
         
     | 
| 
      
 23 
     | 
    
         
            +
             
     | 
| 
      
 24 
     | 
    
         
            +
              module Helpers
         
     | 
| 
      
 25 
     | 
    
         
            +
                autoload :Context, 'model_log/helpers/context'
         
     | 
| 
      
 26 
     | 
    
         
            +
              end
         
     | 
| 
      
 27 
     | 
    
         
            +
             
     | 
| 
       15 
28 
     | 
    
         
             
              class << self
         
     | 
| 
       16 
29 
     | 
    
         
             
                def configure
         
     | 
| 
       17 
30 
     | 
    
         
             
                  yield config
         
     | 
| 
         @@ -26,7 +39,7 @@ module ModelLog 
     | 
|
| 
       26 
39 
     | 
    
         
             
                end
         
     | 
| 
       27 
40 
     | 
    
         | 
| 
       28 
41 
     | 
    
         
             
                def requester
         
     | 
| 
       29 
     | 
    
         
            -
                  Store. 
     | 
| 
      
 42 
     | 
    
         
            +
                  Store.requester
         
     | 
| 
       30 
43 
     | 
    
         
             
                end
         
     | 
| 
       31 
44 
     | 
    
         | 
| 
       32 
45 
     | 
    
         
             
                def requester_exist?
         
     | 
| 
         @@ -40,6 +53,12 @@ module ModelLog 
     | 
|
| 
       40 
53 
     | 
    
         
             
                def current_user_exist?
         
     | 
| 
       41 
54 
     | 
    
         
             
                  !!current_user
         
     | 
| 
       42 
55 
     | 
    
         
             
                end
         
     | 
| 
      
 56 
     | 
    
         
            +
             
     | 
| 
      
 57 
     | 
    
         
            +
                def version
         
     | 
| 
      
 58 
     | 
    
         
            +
                  VERSION::STRING
         
     | 
| 
      
 59 
     | 
    
         
            +
                end
         
     | 
| 
       43 
60 
     | 
    
         
             
              end
         
     | 
| 
       44 
61 
     | 
    
         
             
            end
         
     | 
| 
       45 
62 
     | 
    
         | 
| 
      
 63 
     | 
    
         
            +
            require 'model_log/controller'
         
     | 
| 
      
 64 
     | 
    
         
            +
            require 'model_log/modeller'
         
     | 
    
        data/lib/model_log/config.rb
    CHANGED
    
    | 
         @@ -6,7 +6,7 @@ module ModelLog 
     | 
|
| 
       6 
6 
     | 
    
         
             
                def initialize
         
     | 
| 
       7 
7 
     | 
    
         
             
                  @current_user_method ||= :current_user
         
     | 
| 
       8 
8 
     | 
    
         
             
                  @identity_field      ||= :id
         
     | 
| 
       9 
     | 
    
         
            -
                  @separator           ||=  
     | 
| 
      
 9 
     | 
    
         
            +
                  @separator           ||= ' '
         
     | 
| 
       10 
10 
     | 
    
         
             
                  @formatter           ||= Default::Formatter
         
     | 
| 
       11 
11 
     | 
    
         
             
                  @logger_level        ||= Logger::INFO  # DEBUG < INFO < WARN < ERROR < FATAL < UNKNOWN
         
     | 
| 
       12 
12 
     | 
    
         
             
                end
         
     | 
    
        data/lib/model_log/context.rb
    CHANGED
    
    | 
         @@ -1,13 +1,11 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            module ModelLog
         
     | 
| 
       2 
     | 
    
         
            -
               
     | 
| 
       3 
     | 
    
         
            -
                 
     | 
| 
       4 
     | 
    
         
            -
                   
     | 
| 
       5 
     | 
    
         
            -
             
     | 
| 
       6 
     | 
    
         
            -
                  end
         
     | 
| 
      
 2 
     | 
    
         
            +
              class Context
         
     | 
| 
      
 3 
     | 
    
         
            +
                def initialize(context)
         
     | 
| 
      
 4 
     | 
    
         
            +
                  @context = context
         
     | 
| 
      
 5 
     | 
    
         
            +
                end
         
     | 
| 
       7 
6 
     | 
    
         | 
| 
       8 
     | 
    
         
            -
             
     | 
| 
       9 
     | 
    
         
            -
             
     | 
| 
       10 
     | 
    
         
            -
                  end
         
     | 
| 
      
 7 
     | 
    
         
            +
                def to_struct
         
     | 
| 
      
 8 
     | 
    
         
            +
                  Struct.new(*@context.keys).new(*@context.values)
         
     | 
| 
       11 
9 
     | 
    
         
             
                end
         
     | 
| 
       12 
10 
     | 
    
         
             
              end
         
     | 
| 
       13 
11 
     | 
    
         
             
            end
         
     | 
    
        data/lib/model_log/controller.rb
    CHANGED
    
    | 
         @@ -10,25 +10,25 @@ module ModelLog 
     | 
|
| 
       10 
10 
     | 
    
         
             
                module ClassMethods
         
     | 
| 
       11 
11 
     | 
    
         
             
                  def set_model_log_stroe
         
     | 
| 
       12 
12 
     | 
    
         
             
                    if ::Rails::VERSION::MAJOR > 3
         
     | 
| 
       13 
     | 
    
         
            -
                      before_action : 
     | 
| 
       14 
     | 
    
         
            -
                      before_action : 
     | 
| 
      
 13 
     | 
    
         
            +
                      before_action :set_model_log_current_user
         
     | 
| 
      
 14 
     | 
    
         
            +
                      before_action :set_model_log_requester
         
     | 
| 
       15 
15 
     | 
    
         
             
                    else
         
     | 
| 
       16 
     | 
    
         
            -
                      before_filter : 
     | 
| 
       17 
     | 
    
         
            -
                      before_filter : 
     | 
| 
      
 16 
     | 
    
         
            +
                      before_filter :set_model_log_current_user
         
     | 
| 
      
 17 
     | 
    
         
            +
                      before_filter :set_model_log_requester
         
     | 
| 
       18 
18 
     | 
    
         
             
                    end
         
     | 
| 
       19 
19 
     | 
    
         
             
                  end
         
     | 
| 
       20 
20 
     | 
    
         
             
                end
         
     | 
| 
       21 
21 
     | 
    
         | 
| 
       22 
22 
     | 
    
         
             
                private
         
     | 
| 
       23 
23 
     | 
    
         | 
| 
       24 
     | 
    
         
            -
                def  
     | 
| 
      
 24 
     | 
    
         
            +
                def set_model_log_current_user
         
     | 
| 
       25 
25 
     | 
    
         
             
                  Store.clear_current_user!
         
     | 
| 
       26 
26 
     | 
    
         
             
                  Store.current_user = send(ModelLog.config.current_user_method) rescue nil
         
     | 
| 
       27 
27 
     | 
    
         
             
                end
         
     | 
| 
       28 
28 
     | 
    
         | 
| 
       29 
     | 
    
         
            -
                def  
     | 
| 
       30 
     | 
    
         
            -
                  Store. 
     | 
| 
       31 
     | 
    
         
            -
                  Store. 
     | 
| 
      
 29 
     | 
    
         
            +
                def set_model_log_requester
         
     | 
| 
      
 30 
     | 
    
         
            +
                  Store.clear_requester!
         
     | 
| 
      
 31 
     | 
    
         
            +
                  Store.requester = request.is_a?(ActionDispatch::Request) && request rescue nil
         
     | 
| 
       32 
32 
     | 
    
         
             
                end
         
     | 
| 
       33 
33 
     | 
    
         
             
              end
         
     | 
| 
       34 
34 
     | 
    
         
             
            end
         
     | 
| 
         @@ -18,9 +18,9 @@ module ModelLog 
     | 
|
| 
       18 
18 
     | 
    
         
             
                    Context.new(
         
     | 
| 
       19 
19 
     | 
    
         
             
                      current_user: ModelLog.current_user,
         
     | 
| 
       20 
20 
     | 
    
         
             
                      requester: ModelLog.requester,
         
     | 
| 
       21 
     | 
    
         
            -
                      action:  
     | 
| 
       22 
     | 
    
         
            -
                      resource:  
     | 
| 
       23 
     | 
    
         
            -
                      changes: Processor.new( 
     | 
| 
      
 21 
     | 
    
         
            +
                      action: action,
         
     | 
| 
      
 22 
     | 
    
         
            +
                      resource: resource,
         
     | 
| 
      
 23 
     | 
    
         
            +
                      changes: Processor.new(resource, action).data
         
     | 
| 
       24 
24 
     | 
    
         
             
                    ).to_struct
         
     | 
| 
       25 
25 
     | 
    
         
             
                  end
         
     | 
| 
       26 
26 
     | 
    
         
             
                end
         
     | 
| 
         @@ -1,21 +1,31 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            module ModelLog
         
     | 
| 
       2 
2 
     | 
    
         
             
              module Log
         
     | 
| 
       3 
3 
     | 
    
         
             
                module Initializer
         
     | 
| 
       4 
     | 
    
         
            -
                   
     | 
| 
       5 
     | 
    
         
            -
             
     | 
| 
       6 
     | 
    
         
            -
                  # 
     | 
| 
       7 
     | 
    
         
            -
                  #  
     | 
| 
      
 4 
     | 
    
         
            +
                  attr_reader :resource, :changes, :attributes, :changed_attributes, :action
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
                  # params
         
     | 
| 
      
 7 
     | 
    
         
            +
                  # resource: object_active_record
         
     | 
| 
      
 8 
     | 
    
         
            +
                  # action:   create|update|destroy
         
     | 
| 
       8 
9 
     | 
    
         
             
                  def initialize(resource, action)
         
     | 
| 
       9 
     | 
    
         
            -
                    @ 
     | 
| 
       10 
     | 
    
         
            -
                    @action = action
         
     | 
| 
      
 10 
     | 
    
         
            +
                    @action             = action
         
     | 
| 
       11 
11 
     | 
    
         
             
                    verify_action!
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
                    @resource           = resource
         
     | 
| 
      
 14 
     | 
    
         
            +
                    @changes            = resource.changes
         
     | 
| 
      
 15 
     | 
    
         
            +
                    @changed_attributes = resource.changed_attributes
         
     | 
| 
      
 16 
     | 
    
         
            +
                    @attributes         = resource.attributes
         
     | 
| 
      
 17 
     | 
    
         
            +
                    @is_changed         = resource.changed?
         
     | 
| 
      
 18 
     | 
    
         
            +
                  end
         
     | 
| 
      
 19 
     | 
    
         
            +
             
     | 
| 
      
 20 
     | 
    
         
            +
                  def changd?
         
     | 
| 
      
 21 
     | 
    
         
            +
                    @is_changed
         
     | 
| 
       12 
22 
     | 
    
         
             
                  end
         
     | 
| 
       13 
23 
     | 
    
         | 
| 
       14 
24 
     | 
    
         
             
                  private
         
     | 
| 
       15 
25 
     | 
    
         | 
| 
       16 
26 
     | 
    
         
             
                  def verify_action!
         
     | 
| 
       17 
     | 
    
         
            -
                    unless %i(create destroy update).include?  
     | 
| 
       18 
     | 
    
         
            -
                      raise StandardError, "invalid action given #{ 
     | 
| 
      
 27 
     | 
    
         
            +
                    unless %i(create destroy update).include? action
         
     | 
| 
      
 28 
     | 
    
         
            +
                      raise StandardError, "invalid action given #{action}"
         
     | 
| 
       19 
29 
     | 
    
         
             
                    end
         
     | 
| 
       20 
30 
     | 
    
         
             
                  end
         
     | 
| 
       21 
31 
     | 
    
         
             
                end
         
     | 
| 
         @@ -4,7 +4,7 @@ module ModelLog 
     | 
|
| 
       4 
4 
     | 
    
         
             
                  include Initializer
         
     | 
| 
       5 
5 
     | 
    
         | 
| 
       6 
6 
     | 
    
         
             
                  def data
         
     | 
| 
       7 
     | 
    
         
            -
                    case  
     | 
| 
      
 7 
     | 
    
         
            +
                    case action
         
     | 
| 
       8 
8 
     | 
    
         
             
                    when :create
         
     | 
| 
       9 
9 
     | 
    
         
             
                      created_data
         
     | 
| 
       10 
10 
     | 
    
         
             
                    when :update
         
     | 
| 
         @@ -16,22 +16,17 @@ module ModelLog 
     | 
|
| 
       16 
16 
     | 
    
         | 
| 
       17 
17 
     | 
    
         
             
                  private
         
     | 
| 
       18 
18 
     | 
    
         | 
| 
       19 
     | 
    
         
            -
                  def  
     | 
| 
       20 
     | 
    
         
            -
                     
     | 
| 
      
 19 
     | 
    
         
            +
                  def saved_data
         
     | 
| 
      
 20 
     | 
    
         
            +
                    changes
         
     | 
| 
       21 
21 
     | 
    
         
             
                  end
         
     | 
| 
       22 
22 
     | 
    
         | 
| 
       23 
     | 
    
         
            -
                   
     | 
| 
       24 
     | 
    
         
            -
             
     | 
| 
       25 
     | 
    
         
            -
                    @resource.class.content_columns.map do |column|
         
     | 
| 
       26 
     | 
    
         
            -
                      [column.name, @resource.send(column.name)]
         
     | 
| 
       27 
     | 
    
         
            -
                    end.to_h
         
     | 
| 
       28 
     | 
    
         
            -
                  end
         
     | 
| 
       29 
     | 
    
         
            -
             
     | 
| 
       30 
     | 
    
         
            -
                  alias_method :destroyed_data, :created_data
         
     | 
| 
      
 23 
     | 
    
         
            +
                  alias_method :created_data, :saved_data
         
     | 
| 
      
 24 
     | 
    
         
            +
                  alias_method :updated_data, :saved_data
         
     | 
| 
       31 
25 
     | 
    
         | 
| 
       32 
     | 
    
         
            -
                  def  
     | 
| 
       33 
     | 
    
         
            -
                     
     | 
| 
       34 
     | 
    
         
            -
                     
     | 
| 
      
 26 
     | 
    
         
            +
                  def destroyed_data
         
     | 
| 
      
 27 
     | 
    
         
            +
                    data = attributes
         
     | 
| 
      
 28 
     | 
    
         
            +
                    data = data.merge(changed_attributes) if changd?
         
     | 
| 
      
 29 
     | 
    
         
            +
                    data.map { |attr, value| [attr, [value, nil]] }.to_h
         
     | 
| 
       35 
30 
     | 
    
         
             
                  end
         
     | 
| 
       36 
31 
     | 
    
         
             
                end
         
     | 
| 
       37 
32 
     | 
    
         
             
              end
         
     | 
    
        data/lib/model_log/logger.rb
    CHANGED
    
    
    
        data/lib/model_log/modeller.rb
    CHANGED
    
    | 
         @@ -6,9 +6,9 @@ module ModelLog 
     | 
|
| 
       6 
6 
     | 
    
         | 
| 
       7 
7 
     | 
    
         
             
                module ClassMethods
         
     | 
| 
       8 
8 
     | 
    
         
             
                  def model_log
         
     | 
| 
       9 
     | 
    
         
            -
                     
     | 
| 
       10 
     | 
    
         
            -
                    after_destroy :model_log_destroy
         
     | 
| 
      
 9 
     | 
    
         
            +
                    before_create :model_log_create
         
     | 
| 
       11 
10 
     | 
    
         
             
                    before_update :model_log_update
         
     | 
| 
      
 11 
     | 
    
         
            +
                    after_destroy :model_log_destroy
         
     | 
| 
       12 
12 
     | 
    
         
             
                  end
         
     | 
| 
       13 
13 
     | 
    
         
             
                end
         
     | 
| 
       14 
14 
     | 
    
         | 
| 
         @@ -27,19 +27,10 @@ module ModelLog 
     | 
|
| 
       27 
27 
     | 
    
         
             
                end
         
     | 
| 
       28 
28 
     | 
    
         | 
| 
       29 
29 
     | 
    
         
             
                def model_log_write(resource, action)
         
     | 
| 
       30 
     | 
    
         
            -
                   
     | 
| 
       31 
     | 
    
         
            -
                  # update changes is not empty
         
     | 
| 
       32 
     | 
    
         
            -
                  # create and destroy changes is empty
         
     | 
| 
       33 
     | 
    
         
            -
                  if log_content(resource, action)
         
     | 
| 
       34 
     | 
    
         
            -
                    ModelLog.logger.info log_content(resource, action)
         
     | 
| 
       35 
     | 
    
         
            -
                  end
         
     | 
| 
      
 30 
     | 
    
         
            +
                  ModelLog.logger.info Log::Content.new(resource, action, ModelLog.config.formatter).content
         
     | 
| 
       36 
31 
     | 
    
         
             
                rescue => ex
         
     | 
| 
       37 
32 
     | 
    
         
             
                  ModelLog.logger.error "#{ex.class}: #{ex.message}"
         
     | 
| 
       38 
33 
     | 
    
         
             
                end
         
     | 
| 
       39 
     | 
    
         
            -
             
     | 
| 
       40 
     | 
    
         
            -
                def log_content(resource, action)
         
     | 
| 
       41 
     | 
    
         
            -
                  @log_content ||= Log::Content.new(resource, action, ModelLog.config.formatter).content
         
     | 
| 
       42 
     | 
    
         
            -
                end
         
     | 
| 
       43 
34 
     | 
    
         
             
              end
         
     | 
| 
       44 
35 
     | 
    
         
             
            end
         
     | 
| 
       45 
36 
     | 
    
         | 
    
        data/lib/model_log/store.rb
    CHANGED
    
    | 
         @@ -33,15 +33,15 @@ module ModelLog 
     | 
|
| 
       33 
33 
     | 
    
         
             
                    delete :current_user
         
     | 
| 
       34 
34 
     | 
    
         
             
                  end
         
     | 
| 
       35 
35 
     | 
    
         | 
| 
       36 
     | 
    
         
            -
                  def  
     | 
| 
      
 36 
     | 
    
         
            +
                  def requester
         
     | 
| 
       37 
37 
     | 
    
         
             
                    read :requester
         
     | 
| 
       38 
38 
     | 
    
         
             
                  end
         
     | 
| 
       39 
39 
     | 
    
         | 
| 
       40 
     | 
    
         
            -
                  def  
     | 
| 
       41 
     | 
    
         
            -
                    write :requester,  
     | 
| 
      
 40 
     | 
    
         
            +
                  def requester=(request)
         
     | 
| 
      
 41 
     | 
    
         
            +
                    write :requester, request
         
     | 
| 
       42 
42 
     | 
    
         
             
                  end
         
     | 
| 
       43 
43 
     | 
    
         | 
| 
       44 
     | 
    
         
            -
                  def  
     | 
| 
      
 44 
     | 
    
         
            +
                  def clear_requester!
         
     | 
| 
       45 
45 
     | 
    
         
             
                    delete :requester
         
     | 
| 
       46 
46 
     | 
    
         
             
                  end
         
     | 
| 
       47 
47 
     | 
    
         
             
                end
         
     | 
    
        data/lib/model_log/version.rb
    CHANGED
    
    | 
         @@ -1,3 +1,16 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            module ModelLog
         
     | 
| 
       2 
     | 
    
         
            -
              VERSION 
     | 
| 
      
 2 
     | 
    
         
            +
              module VERSION
         
     | 
| 
      
 3 
     | 
    
         
            +
                MAJOR = 2
         
     | 
| 
      
 4 
     | 
    
         
            +
                MINOR = 0
         
     | 
| 
      
 5 
     | 
    
         
            +
                TINY  = 1
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
                # Set PRE to nil unless it's a pre-release (beta, rc, etc.)
         
     | 
| 
      
 8 
     | 
    
         
            +
                PRE = nil
         
     | 
| 
      
 9 
     | 
    
         
            +
             
     | 
| 
      
 10 
     | 
    
         
            +
                STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".").freeze
         
     | 
| 
      
 11 
     | 
    
         
            +
             
     | 
| 
      
 12 
     | 
    
         
            +
                def self.to_s
         
     | 
| 
      
 13 
     | 
    
         
            +
                  STRING
         
     | 
| 
      
 14 
     | 
    
         
            +
                end
         
     | 
| 
      
 15 
     | 
    
         
            +
              end
         
     | 
| 
       3 
16 
     | 
    
         
             
            end
         
     | 
    
        data/model_log.gemspec
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | 
         @@ -1,14 +1,14 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: model_log
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 2.0. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 2.0.1
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - jk-sun
         
     | 
| 
       8 
8 
     | 
    
         
             
            autorequire: 
         
     | 
| 
       9 
9 
     | 
    
         
             
            bindir: exe
         
     | 
| 
       10 
10 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       11 
     | 
    
         
            -
            date:  
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2020-01-19 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              name: bundler
         
     | 
| 
         @@ -32,7 +32,10 @@ executables: [] 
     | 
|
| 
       32 
32 
     | 
    
         
             
            extensions: []
         
     | 
| 
       33 
33 
     | 
    
         
             
            extra_rdoc_files: []
         
     | 
| 
       34 
34 
     | 
    
         
             
            files:
         
     | 
| 
      
 35 
     | 
    
         
            +
            - ".github/ISSUE_TEMPLATE/bug_report.md"
         
     | 
| 
      
 36 
     | 
    
         
            +
            - ".github/ISSUE_TEMPLATE/feature_request.md"
         
     | 
| 
       35 
37 
     | 
    
         
             
            - ".gitignore"
         
     | 
| 
      
 38 
     | 
    
         
            +
            - ".rspec"
         
     | 
| 
       36 
39 
     | 
    
         
             
            - ".travis.yml"
         
     | 
| 
       37 
40 
     | 
    
         
             
            - CODE_OF_CONDUCT.md
         
     | 
| 
       38 
41 
     | 
    
         
             
            - Gemfile
         
     |