Skip to content

Set up RuboCop with CI #120

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions .github/workflows/rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: RuboCop

on: [push, pull_request]

permissions:
contents: read

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Set up Ruby 3.2
uses: ruby/setup-ruby@v1
with:
ruby-version: 3.2
bundler-cache: true

- name: Run RuboCop
run: bundle exec rubocop --parallel
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
*.gem
.rubocop-*
1 change: 1 addition & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
inherit_from: https://raw.githubusercontent.com/rails/rails/main/.rubocop.yml
8 changes: 8 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
# frozen_string_literal: true

source "https://rubygems.org"

gemspec

gem "rake"
gem "debug", ">= 1.0.0"
gem "rubocop"
gem "rubocop-minitest"
gem "rubocop-packaging"
gem "rubocop-performance"
gem "rubocop-rails"
gem "rubocop-md"
44 changes: 44 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ GEM
minitest (>= 5.1)
tzinfo (~> 2.0)
zeitwerk (~> 2.3)
ast (2.4.2)
builder (3.2.4)
concurrent-ruby (1.1.8)
connection_pool (2.4.1)
Expand All @@ -83,6 +84,8 @@ GEM
io-console (0.6.0)
irb (1.7.1)
reline (>= 0.3.0)
json (2.6.3)
language_server-protocol (3.17.0.3)
loofah (2.9.0)
crass (~> 1.0.2)
nokogiri (>= 1.5.9)
Expand All @@ -101,6 +104,10 @@ GEM
racc (~> 1.4)
nokogiri (1.15.2-x86_64-darwin)
racc (~> 1.4)
parallel (1.23.0)
parser (3.2.2.3)
ast (~> 2.4.1)
racc
racc (1.7.1)
rack (2.2.3)
rack-test (1.1.0)
Expand Down Expand Up @@ -131,13 +138,43 @@ GEM
method_source
rake (>= 0.8.7)
thor (~> 1.0)
rainbow (3.1.1)
rake (13.0.3)
redis (5.0.6)
redis-client (>= 0.9.0)
redis-client (0.14.1)
connection_pool
regexp_parser (2.8.1)
reline (0.3.6)
io-console (~> 0.5)
rexml (3.2.5)
rubocop (1.54.1)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
parallel (~> 1.10)
parser (>= 3.2.2.3)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
rexml (>= 3.2.5, < 4.0)
rubocop-ast (>= 1.28.0, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.29.0)
parser (>= 3.2.1.0)
rubocop-md (1.2.0)
rubocop (>= 1.0)
rubocop-minitest (0.31.0)
rubocop (>= 1.39, < 2.0)
rubocop-packaging (0.5.2)
rubocop (>= 1.33, < 2.0)
rubocop-performance (1.18.0)
rubocop (>= 1.7.0, < 2.0)
rubocop-ast (>= 0.4.0)
rubocop-rails (2.20.2)
activesupport (>= 4.2.0)
rack (>= 1.1)
rubocop (>= 1.33.0, < 2.0)
ruby-progressbar (1.13.0)
sprockets (4.0.2)
concurrent-ruby (~> 1.0)
rack (> 1, < 3)
Expand All @@ -148,6 +185,7 @@ GEM
thor (1.1.0)
tzinfo (2.0.4)
concurrent-ruby (~> 1.0)
unicode-display_width (2.4.2)
websocket-driver (0.7.3)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.5)
Expand All @@ -163,6 +201,12 @@ DEPENDENCIES
kredis!
rails (>= 6.0.0)
rake
rubocop
rubocop-md
rubocop-minitest
rubocop-packaging
rubocop-performance
rubocop-rails

BUNDLED WITH
2.3.12
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ integer.value = 5 # => SET myinteger "5"
5 == integer.value # => GET myinteger

decimal = Kredis.decimal "mydecimal" # accuracy!
decimal.value = "%.47f" % (1.0/10) # => SET mydecimal "0.10000000000000000555111512312578270211815834045"
decimal.value = "%.47f" % (1.0 / 10) # => SET mydecimal "0.10000000000000000555111512312578270211815834045"
BigDecimal("0.10000000000000000555111512312578270211815834045e0") == decimal.value # => GET mydecimal

float = Kredis.float "myfloat" # speed!
float.value = 1.0/10 # => SET myfloat "0.1"
float.value = 1.0 / 10 # => SET myfloat "0.1"
0.1 == float.value # => GET myfloat

boolean = Kredis.boolean "myboolean"
Expand Down Expand Up @@ -228,14 +228,14 @@ If you need to connect to Redis with SSL, the recommended approach is to set you

```ruby
Kredis::Connections.connections[:shared] = Redis.new(
url: ENV['REDIS_URL'],
url: ENV["REDIS_URL"],
ssl_params: {
cert_store: OpenSSL::X509::Store.new.tap { |store|
store.add_file(Rails.root.join('config', 'ca_cert.pem').to_s)
store.add_file(Rails.root.join("config", "ca_cert.pem").to_s)
},

cert: OpenSSL::X509::Certificate.new(File.read(
Rails.root.join('config', 'client.crt')
Rails.root.join("config", "client.crt")
)),

key: OpenSSL::PKey::RSA.new(
Expand Down
1 change: 1 addition & 0 deletions bin/console
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

require "irb"
require "bundler/inline"
Expand Down
2 changes: 2 additions & 0 deletions bin/test
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

$: << File.expand_path("../test", __dir__)

require "bundler/setup"
Expand Down
2 changes: 2 additions & 0 deletions kredis.gemspec
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require_relative "lib/kredis/version"

Gem::Specification.new do |s|
Expand Down
2 changes: 2 additions & 0 deletions lib/install/install.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

yaml_path = Rails.root.join("config/redis/shared.yml")
unless yaml_path.exist?
say "Adding `config/redis/shared.yml`"
Expand Down
2 changes: 2 additions & 0 deletions lib/kredis.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require "active_support"
require "active_support/core_ext/module/attribute_accessors"
require "active_support/core_ext/module/attribute_accessors_per_thread"
Expand Down
4 changes: 3 additions & 1 deletion lib/kredis/attributes.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Kredis::Attributes
extend ActiveSupport::Concern

Expand Down Expand Up @@ -106,7 +108,7 @@ def kredis_key_evaluated(key)
end

def kredis_key_for_attribute(name)
"#{self.class.name.tableize.gsub("/", ":")}:#{extract_kredis_id}:#{name}"
"#{self.class.name.tableize.tr("/", ":")}:#{extract_kredis_id}:#{name}"
end

def extract_kredis_id
Expand Down
6 changes: 3 additions & 3 deletions lib/kredis/connections.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require "redis"

module Kredis::Connections
Expand All @@ -6,11 +8,9 @@ module Kredis::Connections
mattr_accessor :connector, default: ->(config) { Redis.new(config) }

def configured_for(name)
connections[name] ||= begin
Kredis.instrument :meta, message: "Connected to #{name}" do
connections[name] ||= Kredis.instrument :meta, message: "Connected to #{name}" do
connector.call configurator.config_for("redis/#{name}")
end
end
end

def clear_all
Expand Down
2 changes: 2 additions & 0 deletions lib/kredis/log_subscriber.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require "active_support/log_subscriber"

class Kredis::LogSubscriber < ActiveSupport::LogSubscriber
Expand Down
2 changes: 2 additions & 0 deletions lib/kredis/migration.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require "active_support/core_ext/module/delegation"

class Kredis::Migration
Expand Down
2 changes: 2 additions & 0 deletions lib/kredis/namespace.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Kredis::Namespace
def namespace=(namespace)
Thread.current[:kredis_namespace] = namespace
Expand Down
2 changes: 2 additions & 0 deletions lib/kredis/railtie.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class Kredis::Railtie < ::Rails::Railtie
config.kredis = ActiveSupport::OrderedOptions.new

Expand Down
2 changes: 2 additions & 0 deletions lib/kredis/type_casting.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require "json"
require "active_model/type"
require "kredis/type/json"
Expand Down
2 changes: 2 additions & 0 deletions lib/kredis/types.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Kredis::Types
autoload :CallbacksProxy, "kredis/types/callbacks_proxy"

Expand Down
2 changes: 2 additions & 0 deletions lib/kredis/types/callbacks_proxy.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class Kredis::Types::CallbacksProxy
attr_reader :type
delegate :to_s, to: :type
Expand Down
2 changes: 2 additions & 0 deletions lib/kredis/types/counter.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class Kredis::Types::Counter < Kredis::Types::Proxying
proxying :multi, :set, :incrby, :decrby, :get, :del, :exists?

Expand Down
2 changes: 2 additions & 0 deletions lib/kredis/types/cycle.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class Kredis::Types::Cycle < Kredis::Types::Counter
attr_accessor :values

Expand Down
2 changes: 2 additions & 0 deletions lib/kredis/types/enum.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require "active_support/core_ext/object/inclusion"

class Kredis::Types::Enum < Kredis::Types::Proxying
Expand Down
2 changes: 2 additions & 0 deletions lib/kredis/types/flag.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class Kredis::Types::Flag < Kredis::Types::Proxying
proxying :set, :exists?, :del

Expand Down
4 changes: 3 additions & 1 deletion lib/kredis/types/hash.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require "active_support/core_ext/hash"

class Kredis::Types::Hash < Kredis::Types::Proxying
Expand All @@ -14,7 +16,7 @@ def []=(key, value)
end

def update(**entries)
hset entries.transform_values{ |val| type_to_string(val, typed) } if entries.flatten.any?
hset entries.transform_values { |val| type_to_string(val, typed) } if entries.flatten.any?
end

def values_at(*keys)
Expand Down
2 changes: 2 additions & 0 deletions lib/kredis/types/list.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class Kredis::Types::List < Kredis::Types::Proxying
proxying :lrange, :lrem, :lpush, :ltrim, :rpush, :exists?, :del

Expand Down
4 changes: 3 additions & 1 deletion lib/kredis/types/ordered_set.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class Kredis::Types::OrderedSet < Kredis::Types::Proxying
proxying :multi, :zrange, :zrem, :zadd, :zremrangebyrank, :zcard, :exists?, :del

Expand Down Expand Up @@ -42,7 +44,7 @@ def insert(elements, prepending: false)
base_score + incremental_score
end

[ score , element ]
[ score, element ]
end

multi do
Expand Down
2 changes: 2 additions & 0 deletions lib/kredis/types/proxy.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class Kredis::Types::Proxy
require_relative "proxy/failsafe"
include Failsafe
Expand Down
2 changes: 2 additions & 0 deletions lib/kredis/types/proxy/failsafe.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Kredis::Types::Proxy::Failsafe
def initialize(*)
super
Expand Down
2 changes: 2 additions & 0 deletions lib/kredis/types/proxying.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require "active_support/core_ext/module/delegation"

class Kredis::Types::Proxying
Expand Down
2 changes: 2 additions & 0 deletions lib/kredis/types/scalar.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class Kredis::Types::Scalar < Kredis::Types::Proxying
proxying :set, :get, :exists?, :del, :expire, :expireat

Expand Down
2 changes: 2 additions & 0 deletions lib/kredis/types/set.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class Kredis::Types::Set < Kredis::Types::Proxying
proxying :smembers, :sadd, :srem, :multi, :del, :sismember, :scard, :spop, :exists?, :srandmember

Expand Down
2 changes: 2 additions & 0 deletions lib/kredis/types/slots.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class Kredis::Types::Slots < Kredis::Types::Proxying
class NotAvailable < StandardError; end

Expand Down
2 changes: 2 additions & 0 deletions lib/kredis/types/unique_list.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# You'd normally call this a set, but Redis already has another data type for that
class Kredis::Types::UniqueList < Kredis::Types::List
proxying :multi, :ltrim, :exists?
Expand Down
2 changes: 2 additions & 0 deletions lib/kredis/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Kredis
VERSION = "1.5.0"
end
2 changes: 2 additions & 0 deletions lib/tasks/kredis/install.rake
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

namespace :kredis do
desc "Install kredis"
task :install do
Expand Down
2 changes: 2 additions & 0 deletions test/attributes_callbacks_test.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require "test_helper"

class AttributesCallbacksTest < ActiveSupport::TestCase
Expand Down
Loading