paper_trail-sinatra 0.3.0 → 0.4.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA256:
3
- metadata.gz: 02b7ddf0982ce846ee50323035eda996cd94dc3252f1093b520b525a41fc2f22
4
- data.tar.gz: 1248c0a0fd5d0c509396c33308a896fbdc4c559e39a2da63311df2831cea2eaf
2
+ SHA1:
3
+ metadata.gz: 6d6d8c636449a424b7c0abdbc05cc80bdfe79d2a
4
+ data.tar.gz: a0a674060d20173bc2fdc012b91d479043ab5f38
5
5
  SHA512:
6
- metadata.gz: 854c929dd6a47cd3284e5ed1207ebfd5917c1e38348890ff9e7580cfac014fefa42d4fa7b3b7dc3864595a59c33e71300f8a7892eca95ad122a3fefabce25dfe
7
- data.tar.gz: 7137fb6dc2db905aabd5e60bbaf512eae371c32942999b4e3959a52329c4d3f44055392c8650e0f0607d3b28db539a3b81f92ba7f47d5b561e46085fb91aedbc
6
+ metadata.gz: 7e4c53518748ed4db5417ca3c55c345e4e4e29df03e354e3c728800e3568695f674e8b10748b7613afc9d512b7b153337c9fca274fa3424a3ddf58bdb40f6cfa
7
+ data.tar.gz: 0b1a95a6976c92541cfd027e85b61f21aa682c19f9421cd59f0ce354ded240254d5173bd84c0e4f3683412186fe51f58f8a1f63fb2e3f14abb678a21fa4860b9
data/.gitignore CHANGED
@@ -6,6 +6,7 @@
6
6
  /coverage/
7
7
  /doc/
8
8
  /pkg/
9
+ /spec/gemfiles/*.lock
9
10
  /spec/reports/
10
11
  /spec/examples.txt
11
12
  /tmp/
data/.travis.yml ADDED
@@ -0,0 +1,22 @@
1
+ before_install:
2
+ - gem update --system
3
+ - gem update bundler
4
+ before_script:
5
+ - mkdir db
6
+ - touch db/test.sqlite3
7
+ - sqlite3 db/test.sqlite3 < spec/create_db.sql
8
+ gemfile:
9
+ - spec/gemfiles/Gemfile_pt7_sinatra1.rb
10
+ - spec/gemfiles/Gemfile_pt7_sinatra2.rb
11
+ - spec/gemfiles/Gemfile_pt8_sinatra1.rb
12
+ - spec/gemfiles/Gemfile_pt8_sinatra2.rb
13
+ language: ruby
14
+
15
+ # For ruby compatibility, we test the highest and lowest minor versions only.
16
+ rvm:
17
+ - 2.5.0
18
+ - 2.2.9
19
+
20
+ script:
21
+ - bundle exec rspec
22
+ sudo: false
data/CHANGELOG.md CHANGED
@@ -1,5 +1,37 @@
1
1
  # Change Log
2
2
 
3
+ ## Unreleased
4
+
5
+ Breaking Changes
6
+
7
+ - None
8
+
9
+ Added
10
+
11
+ - None
12
+
13
+ Fixed
14
+
15
+ - None
16
+
17
+ ## 0.4.0 (2018-02-22)
18
+
19
+ Breaking Changes
20
+
21
+ - Drop support for activesupport < 4.2 (EoL)
22
+ - Drop support for ruby < 2.2 (EoL, and required by sinatra 2)
23
+
24
+ Added
25
+
26
+ - [#5](https://github.com/jaredbeck/paper_trail-sinatra/pull/5) -
27
+ Two methods familiar to rails users
28
+ - info_for_paper_trail
29
+ - paper_trail_enabled_for_request
30
+
31
+ Fixed
32
+
33
+ - None
34
+
3
35
  ## 0.3.0 (2017-12-10)
4
36
 
5
37
  Breaking Changes
data/README.md CHANGED
@@ -32,12 +32,23 @@ into the `create_versions` migration that was generated into your `db/migrate` d
32
32
 
33
33
  5. Add `has_paper_trail` to the models you want to track.
34
34
 
35
- PaperTrail provides a helper extension that acts similar to the controller mixin
35
+ PaperTrail provides some helper extensions that acts similar to the controller mixin
36
36
  it provides for `Rails` applications.
37
37
 
38
- It will set `PaperTrail.whodunnit` to whatever is returned by a method named
39
- `user_for_paper_trail` which you can define inside your Sinatra Application. (by
40
- default it attempts to invoke a method named `current_user`)
38
+ In your helpers you can override these methods:
39
+
40
+ ```ruby
41
+ # Returns the user who is responsible for any changes that occur.
42
+ # Defaults to current_user.
43
+ user_for_paper_trail
44
+
45
+ # Returns any information about the controller or request that you want
46
+ # PaperTrail to store alongside any changes that occur.
47
+ info_for_paper_trail
48
+
49
+ # Returns `true` (default) or `false` to turn PaperTrail on/off for per request.
50
+ paper_trail_enabled_for_request
51
+ ```
41
52
 
42
53
  If you're using the modular [`Sinatra::Base`][4] style of application, you will
43
54
  need to register the extension:
@@ -1,5 +1,5 @@
1
1
  module PaperTrail
2
2
  module Sinatra
3
- VERSION = "0.3.0"
3
+ VERSION = "0.4.0"
4
4
  end
5
5
  end
@@ -10,7 +10,11 @@ module PaperTrail
10
10
  def self.registered(app)
11
11
  app.use RequestStore::Middleware
12
12
  app.helpers self
13
- app.before { set_paper_trail_whodunnit }
13
+ app.before {
14
+ set_paper_trail_whodunnit
15
+ set_paper_trail_request_info
16
+ set_paper_trail_enabled_for_request
17
+ }
14
18
  end
15
19
 
16
20
  protected
@@ -27,13 +31,55 @@ module PaperTrail
27
31
  current_user
28
32
  end
29
33
 
34
+ # Returns any information about the controller or request that you
35
+ # want PaperTrail to store alongside any changes that occur. By
36
+ # default this returns an empty hash.
37
+ #
38
+ # Override this method in your controller to return a hash of any
39
+ # information you need. The hash's keys must correspond to columns
40
+ # in your `versions` table, so don't forget to add any new columns
41
+ # you need.
42
+ #
43
+ # For example:
44
+ #
45
+ # {:ip => request.remote_ip, :user_agent => request.user_agent}
46
+ #
47
+ # The columns `ip` and `user_agent` must exist in your `versions` # table.
48
+ #
49
+ # Use the `:meta` option to
50
+ # `PaperTrail::Model::ClassMethods.has_paper_trail` to store any extra
51
+ # model-level data you need.
52
+ def info_for_paper_trail
53
+ {}
54
+ end
55
+
56
+ # Returns `true` (default) or `false` depending on whether PaperTrail
57
+ # should be active for the current request.
58
+ #
59
+ # Override this method in your controller to specify when PaperTrail
60
+ # should be off.
61
+ def paper_trail_enabled_for_request
62
+ ::PaperTrail.enabled?
63
+ end
64
+
30
65
  private
31
66
 
32
67
  # Tells PaperTrail who is responsible for any changes that occur.
33
68
  def set_paper_trail_whodunnit
34
- @set_paper_trail_whodunnit_called = true
35
69
  ::PaperTrail.whodunnit = user_for_paper_trail if ::PaperTrail.enabled?
36
70
  end
71
+
72
+ # Tells PaperTrail any information from the controller you want to store
73
+ # alongside any changes that occur.
74
+ def set_paper_trail_request_info
75
+ ::PaperTrail.controller_info = info_for_paper_trail if ::PaperTrail.enabled?
76
+ end
77
+
78
+ # Tells PaperTrail whether versions should be saved in the current
79
+ # request.
80
+ def set_paper_trail_enabled_for_request
81
+ ::PaperTrail.enabled_for_controller = paper_trail_enabled_for_request if ::PaperTrail.enabled?
82
+ end
37
83
  end
38
84
  end
39
85
 
@@ -4,27 +4,26 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'paper_trail/sinatra/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
- spec.name = "paper_trail-sinatra"
8
- spec.version = ::PaperTrail::Sinatra::VERSION
9
- spec.authors = ["Jared Beck"]
10
- spec.email = ["jared@jaredbeck.com"]
7
+ spec.name = "paper_trail-sinatra"
8
+ spec.version = ::PaperTrail::Sinatra::VERSION
9
+ spec.authors = ["Jared Beck"]
10
+ spec.email = ["jared@jaredbeck.com"]
11
11
  spec.licenses = ["GPL-3.0"]
12
- spec.summary = 'Sinatra support for paper_trail'
13
- spec.homepage = 'https://github.com/jaredbeck/paper_trail-sinatra'
14
-
15
- spec.files = `git ls-files -z`.split("\x0").reject do |f|
16
- f.match(%r{^(test|spec|features)/})
12
+ spec.summary = 'Sinatra support for paper_trail'
13
+ spec.homepage = 'https://github.com/jaredbeck/paper_trail-sinatra'
14
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
15
+ f.match(%r{^spec/})
17
16
  end
18
- spec.bindir = "exe"
19
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
17
+ spec.executables = []
20
18
  spec.require_paths = ["lib"]
21
19
 
22
20
  # PT 7 requires ruby >= 2.1.0. We don't technically need the same constraint
23
21
  # in this project, but it's helpful for local development.
24
- spec.required_ruby_version = ">= 2.1.0"
22
+ spec.required_ruby_version = ">= 2.2.0"
25
23
 
26
- spec.add_dependency "activesupport", [">= 4.0", "< 6"]
24
+ spec.add_dependency "activesupport", [">= 4.2", "< 6"]
27
25
 
26
+ # Why constrain bundler? Is there a better way?
28
27
  spec.add_dependency "bundler", "~> 1.13"
29
28
 
30
29
  # This gem should not be used with PT < 7 because both define
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paper_trail-sinatra
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jared Beck
8
8
  autorequire:
9
- bindir: exe
9
+ bindir: bin
10
10
  cert_chain: []
11
- date: 2017-12-10 00:00:00.000000000 Z
11
+ date: 2018-02-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -16,7 +16,7 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '4.0'
19
+ version: '4.2'
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
22
  version: '6'
@@ -26,7 +26,7 @@ dependencies:
26
26
  requirements:
27
27
  - - ">="
28
28
  - !ruby/object:Gem::Version
29
- version: '4.0'
29
+ version: '4.2'
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
32
  version: '6'
@@ -134,6 +134,7 @@ extensions: []
134
134
  extra_rdoc_files: []
135
135
  files:
136
136
  - ".gitignore"
137
+ - ".travis.yml"
137
138
  - CHANGELOG.md
138
139
  - Gemfile
139
140
  - LICENSE
@@ -155,7 +156,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
155
156
  requirements:
156
157
  - - ">="
157
158
  - !ruby/object:Gem::Version
158
- version: 2.1.0
159
+ version: 2.2.0
159
160
  required_rubygems_version: !ruby/object:Gem::Requirement
160
161
  requirements:
161
162
  - - ">="
@@ -163,7 +164,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
163
164
  version: '0'
164
165
  requirements: []
165
166
  rubyforge_project:
166
- rubygems_version: 2.7.2
167
+ rubygems_version: 2.6.14
167
168
  signing_key:
168
169
  specification_version: 4
169
170
  summary: Sinatra support for paper_trail