activerecord_touchy 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 +17 -0
- data/.rspec +3 -0
- data/.rubocop.yml +37 -0
- data/.travis.yml +5 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +41 -0
- data/Rakefile +6 -0
- data/activerecord_touchy.gemspec +31 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/activerecord_touchy.rb +9 -0
- data/lib/activerecord_touchy/associations.rb +37 -0
- data/lib/activerecord_touchy/version.rb +3 -0
- metadata +148 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 8b2cbdc30e00bd2ec20aaee11d4bced2d57b1470
|
4
|
+
data.tar.gz: 05a7eaa39c121d77eedf834f8fba5daea1547544
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6bc1bae5c2ad62e3b9c5bc28e68ceddd710dc3480d14e46fd5d11c086e86f9cfc487c54731c5dd8dbf4708d52efce14132745057056f4fb7093fc7670dd4c7b1
|
7
|
+
data.tar.gz: 135d6393d0f168eed2d583c775051c735367113b3aeb6a7a00e960b95a162f47582755001ab4bb30c79e1e6a1f0d7e01e20153e74b67835160b11100788b0ad2
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
Rails:
|
2
|
+
Enabled: true
|
3
|
+
AllCops:
|
4
|
+
TargetRubyVersion: 2.4
|
5
|
+
TargetRailsVersion: 5.1
|
6
|
+
Metrics/LineLength:
|
7
|
+
Max: 120
|
8
|
+
Metrics/ClassLength:
|
9
|
+
Max: 200
|
10
|
+
Documentation:
|
11
|
+
Enabled: false
|
12
|
+
Style/SignalException:
|
13
|
+
Enabled: false
|
14
|
+
Style/ClassAndModuleChildren:
|
15
|
+
Enabled: false
|
16
|
+
Style/FrozenStringLiteralComment:
|
17
|
+
Enabled: false
|
18
|
+
Style/FormatStringToken:
|
19
|
+
EnforcedStyle: template
|
20
|
+
PercentLiteralDelimiters:
|
21
|
+
PreferredDelimiters:
|
22
|
+
'%i': ()
|
23
|
+
'%w': ()
|
24
|
+
Metrics/ClassLength:
|
25
|
+
Max: 200
|
26
|
+
Metrics/ModuleLength:
|
27
|
+
Exclude:
|
28
|
+
- '**/*_spec.rb'
|
29
|
+
Metrics/BlockLength:
|
30
|
+
Exclude:
|
31
|
+
- 'spec/**/*'
|
32
|
+
- '*.gemspec'
|
33
|
+
Rails/SkipsModelValidations:
|
34
|
+
Exclude:
|
35
|
+
- 'spec/**/*'
|
36
|
+
Rails/ApplicationRecord:
|
37
|
+
Enabled: false
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Vital Ryabchinskiy
|
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
|
+
# ActiverecordTouchy
|
2
|
+
|
3
|
+
|
4
|
+
Extend AR to use `touch` for `has_many` and `has_one` relations
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'activerecord_touchy'
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install activerecord_touchy
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
Setup
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
class User < ActiveRecord::Base
|
28
|
+
has_many :articles, touch: true
|
29
|
+
has_one :profile, touch: true
|
30
|
+
end
|
31
|
+
```
|
32
|
+
|
33
|
+
After changing user object relations `articles` and `profile` will be touched.
|
34
|
+
Associations are required `updated_at` column.
|
35
|
+
|
36
|
+
## Contributing
|
37
|
+
1. Fork it
|
38
|
+
2. Create your feature branch (git checkout -b my-new-feature)
|
39
|
+
3. Commit your changes (git commit -am 'Add some feature')
|
40
|
+
4. Push to the branch (git push origin my-new-feature)
|
41
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'activerecord_touchy/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'activerecord_touchy'
|
8
|
+
spec.version = ActiverecordTouchy::VERSION
|
9
|
+
spec.authors = ['Vital Ryabchinskiy']
|
10
|
+
spec.email = ['vital.ryabchinskiy@gmail.com']
|
11
|
+
|
12
|
+
spec.summary = 'Ability to touch has_many and has_one relations'
|
13
|
+
spec.summary = 'Extend AR to use touch for has_many and has_one relations'
|
14
|
+
spec.homepage = 'https://github.com/vitalinfo/activerecord_touchy'
|
15
|
+
spec.license = 'MIT'
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
18
|
+
f.match(%r{^(test|spec|features)/})
|
19
|
+
end
|
20
|
+
spec.bindir = 'exe'
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
+
spec.require_paths = ['lib']
|
23
|
+
|
24
|
+
spec.add_development_dependency 'bundler', '~> 1.16'
|
25
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
26
|
+
spec.add_development_dependency 'rspec', '~> 3.6'
|
27
|
+
spec.add_development_dependency 'rubocop', '~> 0.50'
|
28
|
+
spec.add_development_dependency 'sqlite3', '~> 1.3'
|
29
|
+
|
30
|
+
spec.add_runtime_dependency 'activerecord', '>= 4.0.0', '<= 6.0'
|
31
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'activerecord_touchy'
|
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(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
require 'active_record'
|
2
|
+
require 'activerecord_touchy/version'
|
3
|
+
require 'activerecord_touchy/associations'
|
4
|
+
|
5
|
+
module ActiverecordTouchy
|
6
|
+
end
|
7
|
+
|
8
|
+
# Extend ActiveRecord::Base with touchy associations
|
9
|
+
ActiveRecord::Base.send :include, ActiverecordTouchy::Associations
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module ActiverecordTouchy
|
2
|
+
module Associations
|
3
|
+
def self.included(base)
|
4
|
+
class << base
|
5
|
+
prepend(ClassMethods)
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
module ClassMethods
|
10
|
+
def has_many(name, scope = nil, options = {}, &extension)
|
11
|
+
touch = (scope.is_a?(Hash) ? scope : options).delete(:touch)
|
12
|
+
result = super
|
13
|
+
|
14
|
+
if touch
|
15
|
+
after_commit do
|
16
|
+
public_send(name).update_all(updated_at: Time.now.utc)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
result
|
21
|
+
end
|
22
|
+
|
23
|
+
def has_one(name, scope = nil, options = {})
|
24
|
+
touch = (scope.is_a?(Hash) ? scope : options).delete(:touch)
|
25
|
+
result = super
|
26
|
+
|
27
|
+
if touch
|
28
|
+
after_commit do
|
29
|
+
public_send(name)&.touch
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
result
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
metadata
ADDED
@@ -0,0 +1,148 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: activerecord_touchy
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Vital Ryabchinskiy
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-11-17 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.16'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.16'
|
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
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.6'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.6'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rubocop
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.50'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.50'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: sqlite3
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.3'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.3'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: activerecord
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 4.0.0
|
90
|
+
- - "<="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '6.0'
|
93
|
+
type: :runtime
|
94
|
+
prerelease: false
|
95
|
+
version_requirements: !ruby/object:Gem::Requirement
|
96
|
+
requirements:
|
97
|
+
- - ">="
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: 4.0.0
|
100
|
+
- - "<="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '6.0'
|
103
|
+
description:
|
104
|
+
email:
|
105
|
+
- vital.ryabchinskiy@gmail.com
|
106
|
+
executables: []
|
107
|
+
extensions: []
|
108
|
+
extra_rdoc_files: []
|
109
|
+
files:
|
110
|
+
- ".gitignore"
|
111
|
+
- ".rspec"
|
112
|
+
- ".rubocop.yml"
|
113
|
+
- ".travis.yml"
|
114
|
+
- Gemfile
|
115
|
+
- LICENSE.txt
|
116
|
+
- README.md
|
117
|
+
- Rakefile
|
118
|
+
- activerecord_touchy.gemspec
|
119
|
+
- bin/console
|
120
|
+
- bin/setup
|
121
|
+
- lib/activerecord_touchy.rb
|
122
|
+
- lib/activerecord_touchy/associations.rb
|
123
|
+
- lib/activerecord_touchy/version.rb
|
124
|
+
homepage: https://github.com/vitalinfo/activerecord_touchy
|
125
|
+
licenses:
|
126
|
+
- MIT
|
127
|
+
metadata: {}
|
128
|
+
post_install_message:
|
129
|
+
rdoc_options: []
|
130
|
+
require_paths:
|
131
|
+
- lib
|
132
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
133
|
+
requirements:
|
134
|
+
- - ">="
|
135
|
+
- !ruby/object:Gem::Version
|
136
|
+
version: '0'
|
137
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
138
|
+
requirements:
|
139
|
+
- - ">="
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: '0'
|
142
|
+
requirements: []
|
143
|
+
rubyforge_project:
|
144
|
+
rubygems_version: 2.6.13
|
145
|
+
signing_key:
|
146
|
+
specification_version: 4
|
147
|
+
summary: Extend AR to use touch for has_many and has_one relations
|
148
|
+
test_files: []
|