active_record-updated_at 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 395371ee4b162e5c5bf8235811222b4097e6ead7
4
- data.tar.gz: d2b3362724771f82de0efb358348025eaf937da7
3
+ metadata.gz: e7e02ac57f228b518bd7cc7126a8cd6671f69378
4
+ data.tar.gz: 23a49a276233f00325ab7ab31b72ace2c3b6eb57
5
5
  SHA512:
6
- metadata.gz: b859883939d611983f98be7d5495e0aaad6888f443548ac7a5fb8bf05e17ba9f5b95ef72d7ff7b006eb982b857e0728c71c53a75f2d5b53f290761fdd98d0f0b
7
- data.tar.gz: 5d9496e37271d9e5c1e0c1b84a03be46cb4b98bd6c6aaaf519d4e0c07abbdc5b037925d85dbcee7eaaf6702cdafcf6357cc2a34878c05514b6eba88e79fdb81f
6
+ metadata.gz: 56b39e970c3d9e6db9ab23e4bf5ca9091543f8ec07916b9f3875d892f68af0e6d88be8bff500b736aba3eb276f47da5949a76fc08e1b8e677269347a808c7dcd
7
+ data.tar.gz: e86f9f6f381e4dc9487e3c187b98d300453c260b24e84cce02553cc75e70597c233f9259ee6464bbc0c8be19bf1cd381e8b97b564fac2b3c0ffacf973c3de601
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- active_record-updated_at (0.0.1)
4
+ active_record-updated_at (0.0.2)
5
5
  activerecord
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # ![LendingHome](https://cloud.githubusercontent.com/assets/2419/19467866/7efa93a8-94c8-11e6-93e7-4375dbb8a7bc.png) active_record-updated_at
2
2
  [![Code Climate](https://codeclimate.com/github/LendingHome/active_record-updated_at/badges/gpa.svg)](https://codeclimate.com/github/LendingHome/active_record-updated_at) [![Coverage](https://codeclimate.com/github/LendingHome/active_record-updated_at/badges/coverage.svg)](https://codeclimate.com/github/LendingHome/active_record-updated_at) [![Gem Version](https://badge.fury.io/rb/active_record-updated_at.svg)](http://badge.fury.io/rb/active_record-updated_at)
3
3
 
4
- > Touch `updated_at` by default with calls to `update_column(s)` and `update_all`
4
+ > Touch `updated_at` by default with calls to `update_all` and `update_column(s)`
5
5
 
6
6
  ## Installation
7
7
 
@@ -19,7 +19,7 @@ The default `ActiveRecord` behavior does not touch `updated_at` when the followi
19
19
  * `ActiveRecord::Base#update_columns`
20
20
  * `ActiveRecord::Relation#update_all`
21
21
 
22
- We **rarely ever have a case to modify data WITHOUT touching `updated_at`** so this gem enables the touching behavior by default. For those rare occassions that we don't want the touching we can wrap these calls in a `disable` block explicitly:
22
+ We **rarely ever have a case to modify data WITHOUT touching `updated_at`** so this gem enables the touching behavior by default. For those rare occasions that we don't want the touching we can wrap these calls in a `disable` block explicitly:
23
23
 
24
24
  ```ruby
25
25
  ActiveRecord::UpdatedAt.disable { User.update_all(role: "member") }
@@ -11,7 +11,7 @@ Gem::Specification.new do |s|
11
11
  s.required_ruby_version = ">= 2.0.0"
12
12
  s.summary = "Touch `updated_at` by default with calls to `update_column(s)` and `update_all`"
13
13
  s.test_files = `git ls-files -- spec/*`.split("\n")
14
- s.version = "0.0.1"
14
+ s.version = "0.0.2"
15
15
 
16
16
  s.add_dependency "activerecord"
17
17
  end
@@ -3,15 +3,17 @@ require_relative "active_record/updated_at/relation"
3
3
 
4
4
  module ActiveRecord
5
5
  module UpdatedAt
6
- ActiveRecord::Relation.send(:prepend, Relation)
6
+ ActiveRecord::Relation.send(:include, Relation)
7
+
8
+ STATE = "#{name}::DISABLED".freeze
7
9
 
8
10
  class << self
9
11
  def disable(state = true)
10
- disabled_was = @disabled
11
- @disabled = state
12
+ disabled_was = Thread.current[STATE]
13
+ Thread.current[STATE] = state
12
14
  yield
13
15
  ensure
14
- @disabled = disabled_was
16
+ Thread.current[STATE] = disabled_was
15
17
  end
16
18
 
17
19
  def enable(&block)
@@ -19,7 +21,7 @@ module ActiveRecord
19
21
  end
20
22
 
21
23
  def enabled?
22
- !@disabled
24
+ !Thread.current[STATE]
23
25
  end
24
26
  end
25
27
  end
@@ -1,7 +1,27 @@
1
1
  module ActiveRecord
2
2
  module UpdatedAt
3
3
  module Relation
4
- def update_all(query, *args, &block)
4
+ def self.included(base)
5
+ base.class_eval do
6
+ # We were originally using `prepend` to inject this behavior
7
+ # directly into the `update_all` method but this was causing
8
+ # `SystemStackError` exceptions when loaded alongside other
9
+ # gems like `newrelic_rpm` which uses alias method chains.
10
+ #
11
+ # It's unlikely NewRelic will change their API anytime soon
12
+ # since they have to support older versions of Ruby which do
13
+ # not support `prepend` so we'll use this deprecated style
14
+ # of method injection.
15
+ #
16
+ # Newer versions of ActiveRecord have already deprecated the
17
+ # old `alias_method_chain` method so we're doing it manually
18
+ # here to avoid deprecation warnings.
19
+ alias_method :update_all_without_updated_at, :update_all
20
+ alias_method :update_all, :update_all_with_updated_at
21
+ end
22
+ end
23
+
24
+ def update_all_with_updated_at(query, *args, &block)
5
25
  attribute_exists = column_names.include?("updated_at")
6
26
  already_specified = Array(query).flatten.grep(/\bupdated_at\b/).any?
7
27
  enabled = UpdatedAt.enabled?
@@ -19,7 +39,7 @@ module ActiveRecord
19
39
  end
20
40
  end
21
41
 
22
- super
42
+ update_all_without_updated_at(query, *args, &block)
23
43
  end
24
44
  end
25
45
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_record-updated_at
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - LendingHome
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-11-09 00:00:00.000000000 Z
11
+ date: 2016-11-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord