fancy_count 1.0.3 → 1.0.4
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/workflows/ci.yml +33 -0
- data/.overcommit.yml +32 -0
- data/CODE_OF_CONDUCT.md +1 -1
- data/Gemfile.lock +1 -1
- data/README.md +78 -4
- data/lib/fancy_count/adapter.rb +2 -1
- data/lib/fancy_count/configuration.rb +2 -1
- data/lib/fancy_count/counter.rb +1 -1
- data/lib/fancy_count/redis_adapter.rb +5 -1
- data/lib/fancy_count/test_adapter.rb +2 -2
- data/lib/fancy_count/version.rb +1 -1
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f7eba097d00915da56ebfc8ce112f599c5401884ca422b582e7f7e35ba76d1b0
|
4
|
+
data.tar.gz: 381241c01bef7612772526f7408692133921acd336b38275a8e3f987f17ba6f0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6ce492065add358e229bcfb5488edf043e8c406a4f073b6d744509b20a98a7c6a853770c1d7019ca2a536e67de6a6c5348ff22cc39c1f9b9f90db6ed0a6cc967
|
7
|
+
data.tar.gz: 94db83e7d5899d2951a915c267b595b55f9fdb4a91bed796262cc8c4b89fe9f93c86d52f93cadfc18dd97a15c1f0883363954a5cf1613c5f54b7511c3129d94d
|
@@ -0,0 +1,33 @@
|
|
1
|
+
name: Tests
|
2
|
+
|
3
|
+
on:
|
4
|
+
pull_request:
|
5
|
+
branches:
|
6
|
+
- '*'
|
7
|
+
push:
|
8
|
+
branches:
|
9
|
+
- main
|
10
|
+
jobs:
|
11
|
+
tests:
|
12
|
+
runs-on: ubuntu-latest
|
13
|
+
strategy:
|
14
|
+
matrix:
|
15
|
+
ruby: [ '2.6', '2.7', '3.0']
|
16
|
+
env:
|
17
|
+
BUNDLE_PATH_RELATIVE_TO_CWD: true
|
18
|
+
|
19
|
+
steps:
|
20
|
+
- uses: actions/checkout@master
|
21
|
+
|
22
|
+
- name: Set up Ruby
|
23
|
+
uses: ruby/setup-ruby@v1
|
24
|
+
with:
|
25
|
+
ruby-version: ${{ matrix.ruby }}
|
26
|
+
bundler: default
|
27
|
+
bundler-cache: true
|
28
|
+
|
29
|
+
- name: StandardRb check
|
30
|
+
run: bundle exec standardrb
|
31
|
+
|
32
|
+
- name: Run tests
|
33
|
+
run: bundle exec rspec spec
|
data/.overcommit.yml
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# Overcommit hooks run automatically on certain git operations, like "git commit".
|
2
|
+
# For a complete list of options that you can use to customize hooks, see:
|
3
|
+
# https://github.com/sds/overcommit
|
4
|
+
|
5
|
+
gemfile: false
|
6
|
+
verify_signatures: false
|
7
|
+
|
8
|
+
PreCommit:
|
9
|
+
BundleCheck:
|
10
|
+
enabled: true
|
11
|
+
|
12
|
+
FixMe:
|
13
|
+
enabled: true
|
14
|
+
keywords: ["FIXME"]
|
15
|
+
exclude:
|
16
|
+
- .overcommit.yml
|
17
|
+
|
18
|
+
LocalPathsInGemfile:
|
19
|
+
enabled: true
|
20
|
+
|
21
|
+
RuboCop:
|
22
|
+
enabled: true
|
23
|
+
required_executable: bundle
|
24
|
+
command: ["bundle", "exec", "standardrb"]
|
25
|
+
on_warn: fail
|
26
|
+
|
27
|
+
YamlSyntax:
|
28
|
+
enabled: true
|
29
|
+
|
30
|
+
PostCheckout:
|
31
|
+
ALL:
|
32
|
+
quiet: true
|
data/CODE_OF_CONDUCT.md
CHANGED
@@ -39,7 +39,7 @@ This Code of Conduct applies within all community spaces, and also applies when
|
|
39
39
|
|
40
40
|
## Enforcement
|
41
41
|
|
42
|
-
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at
|
42
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at developer@companycam.com. All complaints will be reviewed and investigated promptly and fairly.
|
43
43
|
|
44
44
|
All community leaders are obligated to respect the privacy and security of the reporter of any incident.
|
45
45
|
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,8 +1,10 @@
|
|
1
1
|
# FancyCount
|
2
2
|
|
3
|
-
|
3
|
+
🎉 Enhanced counter management for your Ruby on Rails app.
|
4
|
+
|
5
|
+
[](https://github.com/CompanyCam/fancy-count/actions) [](https://badge.fury.io/rb/fancy_count)
|
6
|
+
|
4
7
|
|
5
|
-
TODO: Delete this and the text above, and describe your gem
|
6
8
|
|
7
9
|
## Installation
|
8
10
|
|
@@ -20,15 +22,87 @@ Or install it yourself as:
|
|
20
22
|
|
21
23
|
$ gem install fancy_count
|
22
24
|
|
25
|
+
## Configuration
|
26
|
+
|
27
|
+
Make sure to define which adapter you want to use to persist the counters.
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
# config/initializers/fancy_count.rb
|
31
|
+
|
32
|
+
require 'fancy_count'
|
33
|
+
|
34
|
+
FancyCount.configure do |config|
|
35
|
+
config.adapter = :redis
|
36
|
+
end
|
37
|
+
```
|
38
|
+
|
39
|
+
|
23
40
|
## Usage
|
24
41
|
|
25
|
-
|
42
|
+
Fancy count is dead simple to drop in and get going.
|
43
|
+
|
44
|
+
Example usage in IRB
|
45
|
+
|
46
|
+
```ruby
|
47
|
+
counter = FancyCount::Counter.new('my-counter')
|
48
|
+
counter.increment
|
49
|
+
counter.value # => 1
|
50
|
+
counter.decrement # => 0
|
51
|
+
```
|
52
|
+
|
53
|
+
Example usage in an ActiveRecord Model
|
54
|
+
|
55
|
+
```ruby
|
56
|
+
class Company < ApplicationRecord
|
57
|
+
include FancyCount::HasCountable
|
58
|
+
|
59
|
+
fancy_counter :employees
|
60
|
+
end
|
61
|
+
|
62
|
+
company = Company.new
|
63
|
+
company.fancy_employee_count # => 0
|
64
|
+
company.fancy_employee_counter.increment
|
65
|
+
company.fancy_employee_count # => 1
|
66
|
+
```
|
67
|
+
|
68
|
+
Example Counter Cache
|
69
|
+
|
70
|
+
```ruby
|
71
|
+
class Company < ApplicationRecord
|
72
|
+
include FancyCount::HasCountable
|
73
|
+
|
74
|
+
fancy_counter :employees
|
75
|
+
end
|
76
|
+
|
77
|
+
class Employee < ApplicationRecord
|
78
|
+
include FancyCount::CounterCacheable
|
79
|
+
|
80
|
+
belongs_to :company
|
81
|
+
|
82
|
+
fancy_counter_cache :employees, on: :company
|
83
|
+
end
|
84
|
+
|
85
|
+
company = Company.first
|
86
|
+
company.fancy_employee_count # => 0
|
87
|
+
company.employees.create(name: "bob marley")
|
88
|
+
company.fancy_employee_count # => 1
|
89
|
+
company.employees.destroy_all
|
90
|
+
company.fancy_employee_count # => 0
|
91
|
+
```
|
26
92
|
|
27
93
|
## Development
|
28
94
|
|
29
95
|
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
96
|
|
31
|
-
To install this gem onto your local machine, run `bundle exec rake install`.
|
97
|
+
To install this gem onto your local machine, run `bundle exec rake install`.
|
98
|
+
|
99
|
+
### Releasing a new version
|
100
|
+
|
101
|
+
* install gem-release https://github.com/svenfuchs/gem-release
|
102
|
+
* run `gem bump --version patch` if patching (otherwise switch "patch" out for "minor" or "major")
|
103
|
+
* run `gem tag 1.x.x` replacing the "x" characters with appropriate values
|
104
|
+
* run `git push --tags origin` to push the tags up to Github
|
105
|
+
* Finally, run `gem release` which pushes the gem up to whatever repository (ex: Rubygems)
|
32
106
|
|
33
107
|
## Contributing
|
34
108
|
|
data/lib/fancy_count/adapter.rb
CHANGED
@@ -7,6 +7,7 @@ module FancyCount
|
|
7
7
|
include ActiveSupport::Configurable
|
8
8
|
|
9
9
|
config_accessor :adapter
|
10
|
+
config_accessor :expireat
|
10
11
|
|
11
12
|
ADAPTER_CLASSES = {
|
12
13
|
redis: FancyCount::RedisAdapter,
|
@@ -28,7 +29,7 @@ module FancyCount
|
|
28
29
|
private
|
29
30
|
|
30
31
|
def raise_missing_adapter_error(adapter_name)
|
31
|
-
message = %W
|
32
|
+
message = %W[Missing adapter for #{adapter_name}, valid adapters are #{ADAPTER_CLASSES.keys.join(", ")}]
|
32
33
|
raise FancyCount::MissingAdapterError.new(message)
|
33
34
|
end
|
34
35
|
end
|
data/lib/fancy_count/counter.rb
CHANGED
@@ -3,7 +3,11 @@
|
|
3
3
|
module FancyCount
|
4
4
|
class RedisAdapter < Adapter
|
5
5
|
def counter
|
6
|
-
|
6
|
+
options = {}
|
7
|
+
if @config.expireat
|
8
|
+
options[:expireat] = @config.expireat
|
9
|
+
end
|
10
|
+
@counter ||= Redis::Counter.new(@name, options)
|
7
11
|
end
|
8
12
|
end
|
9
13
|
end
|
data/lib/fancy_count/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fancy_count
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- CompanyCam Engineering
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-10-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -170,7 +170,9 @@ executables: []
|
|
170
170
|
extensions: []
|
171
171
|
extra_rdoc_files: []
|
172
172
|
files:
|
173
|
+
- ".github/workflows/ci.yml"
|
173
174
|
- ".gitignore"
|
175
|
+
- ".overcommit.yml"
|
174
176
|
- ".rspec"
|
175
177
|
- CHANGELOG.md
|
176
178
|
- CODE_OF_CONDUCT.md
|
@@ -214,7 +216,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
214
216
|
- !ruby/object:Gem::Version
|
215
217
|
version: '0'
|
216
218
|
requirements: []
|
217
|
-
rubygems_version: 3.
|
219
|
+
rubygems_version: 3.2.15
|
218
220
|
signing_key:
|
219
221
|
specification_version: 4
|
220
222
|
summary: Yet Another Counter Library
|