fancy_count 1.0.3 → 1.0.4

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
  SHA256:
3
- metadata.gz: b5c280fb7de6316b3e72e4d328410d5c8905566e6f873827db0a5c376dc6a79e
4
- data.tar.gz: 5ef9e946335db750937261deb4d2b6212dec712217301f46ec3e737999f78281
3
+ metadata.gz: f7eba097d00915da56ebfc8ce112f599c5401884ca422b582e7f7e35ba76d1b0
4
+ data.tar.gz: 381241c01bef7612772526f7408692133921acd336b38275a8e3f987f17ba6f0
5
5
  SHA512:
6
- metadata.gz: dba3cd5bcc069fb1b13a852c3e3752d8bda941bf09d1a3e3883243169748e17b39b0f831779930193f77655c891b9026c8dc9afffd7ee1e2cabac2fcbc5119b6
7
- data.tar.gz: b56aabb34bfdf71402e4425e6047aeb9af2ca4e329a43e5667fbef7b264a4fda912397806e641212565a4e161690e7c807a9b154c943c9121d2d84fd82b3ca21
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 TODO: Write your email address. All complaints will be reviewed and investigated promptly and fairly.
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
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- fancy_count (1.0.2)
4
+ fancy_count (1.0.4)
5
5
  activerecord (>= 4.2, < 7)
6
6
  activesupport (>= 4.2, < 7)
7
7
 
data/README.md CHANGED
@@ -1,8 +1,10 @@
1
1
  # FancyCount
2
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/fancy_count`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ 🎉 Enhanced counter management for your Ruby on Rails app.
4
+
5
+ [![Build Status](https://github.com/CompanyCam/fancy-count/workflows/Tests/badge.svg)](https://github.com/CompanyCam/fancy-count/actions) [![Gem Version](https://badge.fury.io/rb/fancy_count.svg)](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
- TODO: Write usage instructions here
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`. 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 the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
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
 
@@ -2,8 +2,9 @@
2
2
 
3
3
  module FancyCount
4
4
  class Adapter
5
- def initialize(name)
5
+ def initialize(name, config)
6
6
  @name = name
7
+ @config = config
7
8
  end
8
9
 
9
10
  def increment
@@ -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{Missing adapter for #{adapter_name}, valid adapters are #{ADAPTER_CLASSES.keys.join(", ")}}
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
@@ -34,7 +34,7 @@ module FancyCount
34
34
  private
35
35
 
36
36
  def adapter
37
- @adapter ||= @config.adapter_class.new(@name)
37
+ @adapter ||= @config.adapter_class.new(@name, @config)
38
38
  end
39
39
  end
40
40
  end
@@ -3,7 +3,11 @@
3
3
  module FancyCount
4
4
  class RedisAdapter < Adapter
5
5
  def counter
6
- @counter ||= Redis::Counter.new(@name)
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
@@ -16,8 +16,8 @@ module FancyCount
16
16
  @@counts = value
17
17
  end
18
18
 
19
- def initialize(name)
20
- super(name)
19
+ def initialize(name, config)
20
+ super(name, config)
21
21
  self.class.counts ||= {}
22
22
  self.class.counts[name] ||= 0
23
23
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module FancyCount
4
- VERSION = "1.0.3"
4
+ VERSION = "1.0.4"
5
5
  end
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.3
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-06-09 00:00:00.000000000 Z
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.1.2
219
+ rubygems_version: 3.2.15
218
220
  signing_key:
219
221
  specification_version: 4
220
222
  summary: Yet Another Counter Library