rails_log_book 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +49 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +41 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/generators/log_book/install_generator.rb +22 -0
- data/lib/generators/log_book/migration.rb +15 -0
- data/lib/generators/log_book/templates/initializer.rb +8 -0
- data/lib/generators/log_book/templates/install.rb +15 -0
- data/lib/log_book/configuration.rb +28 -0
- data/lib/log_book/controller_record.rb +28 -0
- data/lib/log_book/record.rb +33 -0
- data/lib/log_book/recorder.rb +125 -0
- data/lib/log_book/squash_records.rb +39 -0
- data/lib/log_book/version.rb +3 -0
- data/lib/rails_log_book.rb +72 -0
- data/log_book.gemspec +36 -0
- metadata +185 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 762b160793eb148f0dc0d98e1c3b255a9db8e14a
|
4
|
+
data.tar.gz: b86ea86166f27fc36bd2e5d19490ef3a4c9d9798
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 22149b6c8df55afa94045cd6ce4f21a3fcfee6f1bdb8b85621b9778e7a4ba3f073e649d9fa0ed27cd536bd7b9a926547a1eeb4ed8b14cb12ae0b5bdb86e986d2
|
7
|
+
data.tar.gz: eec595a8e59e673c9b913346cf8f74e5f4fb391a0c0d77727ec970e67b7d667608ef5ea4ba81a65738010536e9b7e55ae2c9347a48de6dca52fd4b1375bddb55
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, and in the interest of
|
4
|
+
fostering an open and welcoming community, we pledge to respect all people who
|
5
|
+
contribute through reporting issues, posting feature requests, updating
|
6
|
+
documentation, submitting pull requests or patches, and other activities.
|
7
|
+
|
8
|
+
We are committed to making participation in this project a harassment-free
|
9
|
+
experience for everyone, regardless of level of experience, gender, gender
|
10
|
+
identity and expression, sexual orientation, disability, personal appearance,
|
11
|
+
body size, race, ethnicity, age, religion, or nationality.
|
12
|
+
|
13
|
+
Examples of unacceptable behavior by participants include:
|
14
|
+
|
15
|
+
* The use of sexualized language or imagery
|
16
|
+
* Personal attacks
|
17
|
+
* Trolling or insulting/derogatory comments
|
18
|
+
* Public or private harassment
|
19
|
+
* Publishing other's private information, such as physical or electronic
|
20
|
+
addresses, without explicit permission
|
21
|
+
* Other unethical or unprofessional conduct
|
22
|
+
|
23
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
24
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
25
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
26
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
27
|
+
threatening, offensive, or harmful.
|
28
|
+
|
29
|
+
By adopting this Code of Conduct, project maintainers commit themselves to
|
30
|
+
fairly and consistently applying these principles to every aspect of managing
|
31
|
+
this project. Project maintainers who do not follow or enforce the Code of
|
32
|
+
Conduct may be permanently removed from the project team.
|
33
|
+
|
34
|
+
This code of conduct applies both within project spaces and in public spaces
|
35
|
+
when an individual is representing the project or its community.
|
36
|
+
|
37
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
38
|
+
reported by contacting a project maintainer at d4be4st@gmail.com. All
|
39
|
+
complaints will be reviewed and investigated and will result in a response that
|
40
|
+
is deemed necessary and appropriate to the circumstances. Maintainers are
|
41
|
+
obligated to maintain confidentiality with regard to the reporter of an
|
42
|
+
incident.
|
43
|
+
|
44
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
45
|
+
version 1.3.0, available at
|
46
|
+
[http://contributor-covenant.org/version/1/3/0/][version]
|
47
|
+
|
48
|
+
[homepage]: http://contributor-covenant.org
|
49
|
+
[version]: http://contributor-covenant.org/version/1/3/0/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Stjepan Hadjic
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# LogBook
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/log_book`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'log_book'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install log_book
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/log_book. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
36
|
+
|
37
|
+
|
38
|
+
## License
|
39
|
+
|
40
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
41
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "log_book"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
require "pry"
|
11
|
+
Pry.start
|
12
|
+
|
13
|
+
# require "irb"
|
14
|
+
# IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'rails/generators/migration'
|
2
|
+
require 'generators/log_book/migration'
|
3
|
+
require 'log_book'
|
4
|
+
|
5
|
+
module LogBook
|
6
|
+
module Generators
|
7
|
+
class InstallGenerator < Rails::Generators::Base
|
8
|
+
include Rails::Generators::Migration
|
9
|
+
extend LogBook::Generators::Migration
|
10
|
+
|
11
|
+
source_root File.expand_path('../templates', __FILE__)
|
12
|
+
|
13
|
+
def copy_initalizer
|
14
|
+
copy_file 'initializer.rb', 'config/initializers/log_book.rb'
|
15
|
+
end
|
16
|
+
|
17
|
+
def copy_migration
|
18
|
+
migration_template 'install.rb', 'db/migrate/install_log_book.rb'
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module LogBook
|
2
|
+
module Generators
|
3
|
+
module Migration
|
4
|
+
# Implement the required interface for Rails::Generators::Migration.
|
5
|
+
def next_migration_number(dirname) #:nodoc:
|
6
|
+
next_migration_number = current_migration_number(dirname) + 1
|
7
|
+
if ::ActiveRecord::Base.timestamped_migrations
|
8
|
+
[Time.now.utc.strftime("%Y%m%d%H%M%S"), "%.14d" % next_migration_number].max
|
9
|
+
else
|
10
|
+
"%.3d" % next_migration_number
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,8 @@
|
|
1
|
+
LogBook.configure do |config|
|
2
|
+
# config.records_table_name = 'records'
|
3
|
+
# config.ignored_attributes = [:updated_at, :created_at]
|
4
|
+
# config.author_method = :current_user
|
5
|
+
# config.recording_enabled = false
|
6
|
+
# config.record_squashing = true
|
7
|
+
# config.skip_if_empty_actions = [:update]
|
8
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class <%= migration_class_name %> < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
create_table :records do |t|
|
4
|
+
t.belongs_to :author, polymorphic: true, index: true
|
5
|
+
t.belongs_to :subject, polymorphic: true, index: true
|
6
|
+
t.belongs_to :parent, polymorphic: true, index: true
|
7
|
+
t.jsonb :record_changes, default: {}
|
8
|
+
t.jsonb :meta, default: {}
|
9
|
+
t.string :request_uuid
|
10
|
+
t.string :action
|
11
|
+
|
12
|
+
t.datetime :created_at
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module LogBook
|
2
|
+
def self.configure
|
3
|
+
@configuration ||= Configuration.new
|
4
|
+
yield(@configuration)
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.config
|
8
|
+
@configuration ||= Configuration.new
|
9
|
+
end
|
10
|
+
|
11
|
+
class Configuration
|
12
|
+
attr_accessor :records_table_name
|
13
|
+
attr_accessor :ignored_attributes
|
14
|
+
attr_accessor :recording_enabled
|
15
|
+
attr_accessor :author_method
|
16
|
+
attr_accessor :record_squashing
|
17
|
+
attr_accessor :skip_if_empty_actions
|
18
|
+
|
19
|
+
def initialize
|
20
|
+
@records_table_name = 'records'
|
21
|
+
@ignored_attributes = [:updated_at, :created_at]
|
22
|
+
@author_method = :current_user
|
23
|
+
@record_squashing = false
|
24
|
+
@recording_enabled = false
|
25
|
+
@skip_if_empty_actions = [:update]
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module LogBook
|
2
|
+
module ControllerRecord
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
included do
|
6
|
+
before_action :enable_recording
|
7
|
+
around_action :record_squashing
|
8
|
+
end
|
9
|
+
|
10
|
+
def enable_recording
|
11
|
+
LogBook.store[:controller] = self
|
12
|
+
LogBook.store[:author] = current_author
|
13
|
+
LogBook.store[:request_uuid] = try(:request).try(:uuid) || SecureRandom.hex
|
14
|
+
LogBook.enable_recording
|
15
|
+
end
|
16
|
+
|
17
|
+
def record_squashing
|
18
|
+
LogBook.with_record_squashing do
|
19
|
+
yield
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def current_author
|
24
|
+
raise NotImplementedError unless respond_to?(LogBook.config.author_method)
|
25
|
+
send(LogBook.config.author_method)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module LogBook
|
2
|
+
class Record < ActiveRecord::Base
|
3
|
+
self.table_name = LogBook.config.records_table_name
|
4
|
+
|
5
|
+
belongs_to :subject, polymorphic: true
|
6
|
+
belongs_to :author, polymorphic: true
|
7
|
+
belongs_to :parent, polymorphic: true
|
8
|
+
|
9
|
+
before_create :set_request_uuid
|
10
|
+
|
11
|
+
def self.collection_cache_key(collection = all, timestamp_column = :created_at)
|
12
|
+
super(collection, timestamp_column)
|
13
|
+
end
|
14
|
+
|
15
|
+
def subject_key
|
16
|
+
subject.class.table_name
|
17
|
+
end
|
18
|
+
|
19
|
+
def changes_to_record?
|
20
|
+
!(record_changes == {} && skip_if_empty_actions.include?(action))
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def set_request_uuid
|
26
|
+
self.request_uuid ||= LogBook.store[:request_uuid] || SecureRandom.uuid
|
27
|
+
end
|
28
|
+
|
29
|
+
def skip_if_empty_actions
|
30
|
+
(subject.recording_options[:skip_if_empty_actions] || LogBook.config.skip_if_empty_actions).map(&:to_s)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,125 @@
|
|
1
|
+
module LogBook
|
2
|
+
module Recorder
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
module ClassMethods
|
6
|
+
def has_log_book_records(options = {})
|
7
|
+
class_attribute :recording_options, instance_writer: false
|
8
|
+
|
9
|
+
self.recording_options = options
|
10
|
+
|
11
|
+
has_many :records, -> { order(created_at: :asc) }, as: :subject, class_name: 'LogBook::Record'
|
12
|
+
|
13
|
+
on = Array.wrap(options[:on])
|
14
|
+
after_create :create_record if on.empty? || on.include?(:create)
|
15
|
+
after_update :update_record if on.empty? || on.include?(:update)
|
16
|
+
after_destroy :destroy_record if on.empty? || on.include?(:destroy)
|
17
|
+
|
18
|
+
extend LogBook::Recorder::RecordingClassMethods
|
19
|
+
include LogBook::Recorder::RecordingInstanceMethods
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
module RecordingInstanceMethods
|
24
|
+
def to_squash?
|
25
|
+
recording_options[:squash]
|
26
|
+
end
|
27
|
+
|
28
|
+
def save_with_recording
|
29
|
+
with_recording { save }
|
30
|
+
end
|
31
|
+
|
32
|
+
def with_recording(&block)
|
33
|
+
self.class.with_recording(&block)
|
34
|
+
end
|
35
|
+
|
36
|
+
def new_record
|
37
|
+
record = LogBook::Record.new(
|
38
|
+
action: LogBook.store[:action],
|
39
|
+
record_changes: record_changes,
|
40
|
+
author: LogBook.store[:author],
|
41
|
+
subject: self,
|
42
|
+
meta: {}
|
43
|
+
)
|
44
|
+
record.meta = log_book_meta_info(record) if recording_options[:meta].present?
|
45
|
+
record.parent = send(recording_options[:parent]) if recording_options[:parent].present?
|
46
|
+
record
|
47
|
+
end
|
48
|
+
|
49
|
+
def recording_attributes
|
50
|
+
attributes.except(*non_recording_columns)
|
51
|
+
end
|
52
|
+
|
53
|
+
def non_recording_columns
|
54
|
+
self.class.non_recording_columns
|
55
|
+
end
|
56
|
+
|
57
|
+
private
|
58
|
+
|
59
|
+
def record_changes
|
60
|
+
if recording_options[:only]
|
61
|
+
recording_columns = self.class.recording_columns.map(&:name)
|
62
|
+
changes.slice(*recording_columns)
|
63
|
+
else
|
64
|
+
changes.except(*non_recording_columns)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def create_record
|
69
|
+
write_record(:create)
|
70
|
+
end
|
71
|
+
|
72
|
+
def update_record
|
73
|
+
write_record(:update)
|
74
|
+
end
|
75
|
+
|
76
|
+
def destroy_record
|
77
|
+
write_record(:destroy)
|
78
|
+
end
|
79
|
+
|
80
|
+
def write_record(action)
|
81
|
+
return unless LogBook.recording_enabled
|
82
|
+
LogBook.store[:action] ||= action
|
83
|
+
record = new_record
|
84
|
+
return unless record.changes_to_record?
|
85
|
+
record.save
|
86
|
+
end
|
87
|
+
|
88
|
+
def log_book_meta_info(record)
|
89
|
+
case recording_options[:meta]
|
90
|
+
when NilClass then nil
|
91
|
+
when Symbol then send(recording_options[:meta], record)
|
92
|
+
when Proc then recording_options[:meta].call(self, record)
|
93
|
+
when TrueClass then log_book_meta(record)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
def log_book_meta(_record)
|
98
|
+
raise NotImplementedError
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
module RecordingClassMethods
|
103
|
+
def recording_columns
|
104
|
+
columns.select { |c| !non_recording_columns.include?(c.name) }
|
105
|
+
end
|
106
|
+
|
107
|
+
def non_recording_columns
|
108
|
+
@non_recording_columns ||= begin
|
109
|
+
options = recording_options
|
110
|
+
if options[:only]
|
111
|
+
except = column_names - Array.wrap(options[:only]).flatten.map(&:to_s)
|
112
|
+
else
|
113
|
+
except = default_ignored_attributes
|
114
|
+
except |= Array(options[:except]).collect(&:to_s) if options[:except]
|
115
|
+
end
|
116
|
+
except
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
def default_ignored_attributes
|
121
|
+
[primary_key, inheritance_column, *Array.wrap(LogBook.config.ignored_attributes)]
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module LogBook
|
2
|
+
class SquashRecords
|
3
|
+
def initialize(records)
|
4
|
+
@records = records
|
5
|
+
end
|
6
|
+
|
7
|
+
def call
|
8
|
+
records.group_by(&:parent).each do |parent, children|
|
9
|
+
next if parent.nil?
|
10
|
+
children_to_squash = children.select { |child| child.subject.try(:to_squash?) }
|
11
|
+
next if children_to_squash.empty?
|
12
|
+
|
13
|
+
parent_in_records = parent_in_records(parent)
|
14
|
+
parent_in_records.record_changes.merge!(squashed_changes(children_to_squash, :record_changes))
|
15
|
+
parent_in_records.meta.merge!(squashed_changes(children_to_squash, :meta))
|
16
|
+
parent_in_records.created_at ||= children_to_squash.first.created_at
|
17
|
+
parent_in_records.save
|
18
|
+
|
19
|
+
children_to_squash.each(&:delete)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
attr_reader :records
|
26
|
+
|
27
|
+
def squashed_changes(children, key)
|
28
|
+
children.each_with_object({}) do |record, object|
|
29
|
+
object[record.subject_key] ||= {}
|
30
|
+
object[record.subject_key][record.subject_id] = record.send(key)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def parent_in_records(parent)
|
35
|
+
records.find { |record| record.subject == parent } ||
|
36
|
+
parent.new_record
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require 'active_record'
|
2
|
+
require 'request_store'
|
3
|
+
require 'log_book/configuration'
|
4
|
+
require 'log_book/squash_records'
|
5
|
+
require 'log_book/record'
|
6
|
+
require 'log_book/recorder'
|
7
|
+
require 'log_book/controller_record'
|
8
|
+
require 'log_book/version'
|
9
|
+
|
10
|
+
module LogBook
|
11
|
+
class << self
|
12
|
+
def store
|
13
|
+
RequestStore.store[:log_book] ||= {}
|
14
|
+
end
|
15
|
+
|
16
|
+
def with_recording
|
17
|
+
recording_was_disabled = recording_enabled
|
18
|
+
enable_recording
|
19
|
+
yield
|
20
|
+
ensure
|
21
|
+
disable_recording unless recording_was_disabled
|
22
|
+
end
|
23
|
+
|
24
|
+
def without_recording
|
25
|
+
recording_was_enabled = recording_enabled
|
26
|
+
disable_recording
|
27
|
+
yield
|
28
|
+
ensure
|
29
|
+
enable_recording unless recording_was_enabled
|
30
|
+
end
|
31
|
+
|
32
|
+
def record_as(author)
|
33
|
+
prev_author = LogBook.store[:author]
|
34
|
+
LogBook.store[:author] = author
|
35
|
+
yield
|
36
|
+
ensure
|
37
|
+
LogBook.store[:author] = prev_author
|
38
|
+
end
|
39
|
+
|
40
|
+
def with_record_squashing
|
41
|
+
yield
|
42
|
+
squash_records if record_squashing_enabled
|
43
|
+
end
|
44
|
+
|
45
|
+
def recording_enabled
|
46
|
+
LogBook.store.fetch(:recording_enabled, false)
|
47
|
+
end
|
48
|
+
|
49
|
+
def record_squashing_enabled
|
50
|
+
LogBook.store.fetch(:record_squashing, LogBook.config.record_squashing)
|
51
|
+
end
|
52
|
+
|
53
|
+
def disable_recording
|
54
|
+
LogBook.recording_enabled = false
|
55
|
+
end
|
56
|
+
|
57
|
+
def enable_recording
|
58
|
+
LogBook.recording_enabled = true
|
59
|
+
end
|
60
|
+
|
61
|
+
def recording_enabled=(val)
|
62
|
+
LogBook.store[:recording_enabled] = val
|
63
|
+
end
|
64
|
+
|
65
|
+
def squash_records
|
66
|
+
return if LogBook.store[:request_uuid].nil?
|
67
|
+
records = LogBook::Record.where(request_uuid: LogBook.store[:request_uuid])
|
68
|
+
return if records.empty?
|
69
|
+
LogBook::SquashRecords.new(records).call
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
data/log_book.gemspec
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
lib = File.expand_path('../lib', __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require 'log_book/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'rails_log_book'
|
7
|
+
spec.version = LogBook::VERSION
|
8
|
+
spec.authors = ['Stjepan Hadjic']
|
9
|
+
spec.email = ['d4be4st@gmail.com']
|
10
|
+
|
11
|
+
spec.summary = 'Write a short summary, because Rubygems requires one.'
|
12
|
+
spec.description = 'Write a longer description or delete this line.'
|
13
|
+
spec.homepage = 'https://github.com/infinum/rails_log_book'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
17
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
18
|
+
if spec.respond_to?(:metadata)
|
19
|
+
spec.metadata['allowed_push_host'] = 'https://rubygems.org'
|
20
|
+
else
|
21
|
+
raise 'RubyGems 2.0 or newer is required to protect against public gem pushes.'
|
22
|
+
end
|
23
|
+
|
24
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(spec)/}) }
|
25
|
+
spec.require_paths = ['lib']
|
26
|
+
|
27
|
+
spec.add_development_dependency 'bundler', '~> 1.12'
|
28
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
29
|
+
spec.add_development_dependency 'rspec-rails'
|
30
|
+
spec.add_development_dependency 'rails'
|
31
|
+
spec.add_development_dependency 'pg'
|
32
|
+
spec.add_development_dependency 'pry-byebug'
|
33
|
+
|
34
|
+
spec.add_dependency 'request_store'
|
35
|
+
spec.add_dependency 'activerecord', '>= 4.0', '< 5.1'
|
36
|
+
end
|
metadata
ADDED
@@ -0,0 +1,185 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rails_log_book
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Stjepan Hadjic
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-02-20 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.12'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.12'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec-rails
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rails
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: pg
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: pry-byebug
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: request_store
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: activerecord
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '4.0'
|
118
|
+
- - "<"
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: '5.1'
|
121
|
+
type: :runtime
|
122
|
+
prerelease: false
|
123
|
+
version_requirements: !ruby/object:Gem::Requirement
|
124
|
+
requirements:
|
125
|
+
- - ">="
|
126
|
+
- !ruby/object:Gem::Version
|
127
|
+
version: '4.0'
|
128
|
+
- - "<"
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: '5.1'
|
131
|
+
description: Write a longer description or delete this line.
|
132
|
+
email:
|
133
|
+
- d4be4st@gmail.com
|
134
|
+
executables: []
|
135
|
+
extensions: []
|
136
|
+
extra_rdoc_files: []
|
137
|
+
files:
|
138
|
+
- ".gitignore"
|
139
|
+
- ".rspec"
|
140
|
+
- ".travis.yml"
|
141
|
+
- CODE_OF_CONDUCT.md
|
142
|
+
- Gemfile
|
143
|
+
- LICENSE.txt
|
144
|
+
- README.md
|
145
|
+
- Rakefile
|
146
|
+
- bin/console
|
147
|
+
- bin/setup
|
148
|
+
- lib/generators/log_book/install_generator.rb
|
149
|
+
- lib/generators/log_book/migration.rb
|
150
|
+
- lib/generators/log_book/templates/initializer.rb
|
151
|
+
- lib/generators/log_book/templates/install.rb
|
152
|
+
- lib/log_book/configuration.rb
|
153
|
+
- lib/log_book/controller_record.rb
|
154
|
+
- lib/log_book/record.rb
|
155
|
+
- lib/log_book/recorder.rb
|
156
|
+
- lib/log_book/squash_records.rb
|
157
|
+
- lib/log_book/version.rb
|
158
|
+
- lib/rails_log_book.rb
|
159
|
+
- log_book.gemspec
|
160
|
+
homepage: https://github.com/infinum/rails_log_book
|
161
|
+
licenses:
|
162
|
+
- MIT
|
163
|
+
metadata:
|
164
|
+
allowed_push_host: https://rubygems.org
|
165
|
+
post_install_message:
|
166
|
+
rdoc_options: []
|
167
|
+
require_paths:
|
168
|
+
- lib
|
169
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - ">="
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '0'
|
174
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
175
|
+
requirements:
|
176
|
+
- - ">="
|
177
|
+
- !ruby/object:Gem::Version
|
178
|
+
version: '0'
|
179
|
+
requirements: []
|
180
|
+
rubyforge_project:
|
181
|
+
rubygems_version: 2.5.1
|
182
|
+
signing_key:
|
183
|
+
specification_version: 4
|
184
|
+
summary: Write a short summary, because Rubygems requires one.
|
185
|
+
test_files: []
|